Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   TTreeview : Parent, Level etc..... (https://www.delphipraxis.net/211664-ttreeview-parent-level-etc.html)

creehawk 20. Okt 2022 09:42

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:
Wird auch hübsch angezeigt wie es sein soll:
data
--cdlc04
----graphics
------vehicles
--------airship
-----------anim
-----------maps
-----------rdm      <<
--------command_Ship   
-----------anim
-----------maps
-----------rdm
Wenn ich jetzt den Eintrag rdm auswähle hätte ich als Ausgabe gern den Pfad : «data\cdlc04\graphics\vehicles\airship\rdm»

Ich habe das schon mal gemacht, irgendwas mit Level Parent usw. Aber ich hänge irgendwie fest...wie mache ich das?

creehawk

peterbelow 20. Okt 2022 10:32

AW: TTreeview : Parent, Level etc.....
 
Sowas wie
Delphi-Quellcode:
function GetNodePath(aNode: TTreenode): string;
begin
  if not Assigned(aNode.Parent) then
    Result := aNode.Text
  else
    Result := GetNodePath(aNode.Parent) + '\' + aNode.Text;
end;
Untested!

himitsu 20. Okt 2022 10:45

AW: TTreeview : Parent, Level etc.....
 
Iterativ anstatt rekursiv ist eh oftmals angenehmer

Delphi-Quellcode:
function GetNodePath(aNode: TTreenode): string;
begin
  Result := '';
  while Assigned(aNode) do begin
    Result := aNode.Text + '\' + Result;
    aNode := aNode.Parent;
  end;
end;
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
Delphi-Quellcode:
  end;
  Delete(Result, Length(Result), 1); // oder SetLength(Result, Length(Result) - 1);
end;
oder halt
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;

creehawk 20. Okt 2022 13:39

AW: TTreeview : Parent, Level etc.....
 
Vielen Dank, läuft.

Ich hab' zu kompliziert gedacht .... :cry:

creehawk


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:50 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz