![]() |
TTreeview : Parent, Level etc.....
Moin Moin.
Ich lese diese XML in eine TTReeview ein:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<PathesList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Path>data\cdlc04\graphics\vehicles\airship\</Path> <Path>data\cdlc04\graphics\vehicles\airship\anim\</Path> <Path>data\cdlc04\graphics\vehicles\airship\maps\</Path> <Path>data\cdlc04\graphics\vehicles\airship\rdm\</Path> <Path>data\cdlc04\graphics\vehicles\command_ship\</Path> <Path>data\cdlc04\graphics\vehicles\command_ship\anims\</Path> <Path>data\cdlc04\graphics\vehicles\command_ship\maps\</Path> <Path>data\cdlc04\graphics\vehicles\command_ship\rdm\</Path> ... ... usw. </PathesList>
Code:
Wenn ich jetzt den Eintrag rdm auswähle hätte ich als Ausgabe gern den Pfad : «data\cdlc04\graphics\vehicles\airship\rdm»
Wird auch hübsch angezeigt wie es sein soll:
data --cdlc04 ----graphics ------vehicles --------airship -----------anim -----------maps -----------rdm << --------command_Ship -----------anim -----------maps -----------rdm Ich habe das schon mal gemacht, irgendwas mit Level Parent usw. Aber ich hänge irgendwie fest...wie mache ich das? creehawk |
AW: TTreeview : Parent, Level etc.....
Sowas wie
Delphi-Quellcode:
Untested!
function GetNodePath(aNode: TTreenode): string;
begin if not Assigned(aNode.Parent) then Result := aNode.Text else Result := GetNodePath(aNode.Parent) + '\' + aNode.Text; end; |
AW: TTreeview : Parent, Level etc.....
Iterativ anstatt rekursiv ist eh oftmals angenehmer
Delphi-Quellcode:
bzw., wenn jemanden das erste \ stört ... könnte man auch mit IF/IfThen garnicht erst einfügen, anstatt nachträglich zu löschen, aber bin zu faul
function GetNodePath(aNode: TTreenode): string;
begin Result := ''; while Assigned(aNode) do begin Result := aNode.Text + '\' + Result; aNode := aNode.Parent; end; end;
Delphi-Quellcode:
oder halt
end;
Delete(Result, Length(Result), 1); // oder SetLength(Result, Length(Result) - 1); end;
Delphi-Quellcode:
function GetNodePath(aNode: TTreenode): string;
begin Result := aNode.Text; aNode := aNode.Parent; // oder mit eigener lokaler Variable, anstatt aNode while Assigned(aNode) do begin Result := aNode.Text + '\' + Result; aNode := aNode.Parent; end; end; |
AW: TTreeview : Parent, Level etc.....
Vielen Dank, läuft.
Ich hab' zu kompliziert gedacht .... :cry: creehawk |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:14 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz