Autor Beitrag
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 19.05.03 12:01 
den Node-Pfad (als String) in einer TreeView ermitteln?

Möchte man den Pfad einer Node ermitteln reicht der Aufruf der folgenden Funktion:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Function GetTreeNodePath (aNode: TTreeNode; aDiv: String): String;
Begin
  If Assigned (aNode) Then
    If Assigned (aNode.Parent) Then
      GetTreeNodePath := GetTreeNodePath (aNode.Parent, aDiv) + aDiv + aNode.Text
    Else
      GetTreeNodePath := aNode.Text
  Else
    GetTreeNodePath := '';
End;

Diese Funktion kann zum Beispiel in dem OnChange-Event einer TreeView aufgerufen werden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode); 
begin 
  Label1.Caption := GetTreeNodePath (Node, '/');
  // oder
  // Label1.Caption := GetTreeNodePath (Node, ' -> ');
end;

Moderiert von user profile iconjasocul: Beitrag geprüft am 22.05.2006