Autor Beitrag
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Fr 27.06.08 16:43 
HI,

ich arbeite heute das 1. mal mit dem TTreeNode und hab schon das 1. Problem gefunden:
ich will wenn ich ein Node im Tree selektiert hab die Indexe aller ParentNodes.
also den Weg über die nodes zozusagen.
Bsp:
Moderiert von user profile iconNarses: Bild als Anhang hochgeladen
hier wäre der Weg 0-1-0

Ich hab bis jetzt bloß Index und AbsolutIndex als eigenschaft gefunden, und ich wüsste
jetzt nich, wie ich mir damit den Weg zusammen bauen sollte. Kann da jmd helfen?

MfG & Thx Bergmann.
Einloggen, um Attachments anzusehen!
wazup
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 101

Windows XP
Delphi 2009
BeitragVerfasst: Fr 27.06.08 17:20 
Naja... Mal so auf die schnelle gesagt würd ich es so machen:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
function GetWayToNode(const ANode: TTreeNode): string;
var
  Node: TTreeNode;
  Stop: Boolean;
  Temp: string;
  I: Integer;
begin
  Result := '';

  { Wenn keine Node ausgewählt ist, abbrechen }
  if ANode = NIL then
    Exit;

  { Variablen Initalisieren }
  Stop := false;
  Node := ANode;
  Temp := IntToStr(Node.Index);

  while not Stop do
  begin
    if Node.Parent = NIL then Stop := true // Wenn es keine Parent Node gibt aus der schleife springen
    else begin
      Node := Node.Parent; // Parent Node holen
      Temp := Temp + '-' + IntToStr(Node.Index); // Index hinzufügen
    end;
  end;

  { Denn weg zur Node drehen }
  for I := Length(Temp) downto 1 do
    Result := Result + Temp[I];
end;

[...]

procedure TForm1.TreeView1Click(Sender: TObject);
begin
  Caption := GetWayToNode(TreeView1.Selected);
end;


cu, wazup
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 27.06.08 17:31 
Moin!

Schonmal in die FAQ geschaut, ob da was bei ist? :les: :think: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
wazup
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 101

Windows XP
Delphi 2009
BeitragVerfasst: Fr 27.06.08 17:36 
Naja... Ich finde das meine Methode am einfachsten ist und genau darauf zu trifft was unser kollege möchte... :roll:
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Fr 27.06.08 18:48 
Hallo,

da finde ich den Weg den user profile iconTino vorschlägt, besser/flexibler, man kann den Delimeter angeben. :arrow: Link (ist auch auf der Seite die user profile iconNarses verlinkt hat enthalten).

@user profile iconwazup
Deinen Lösungsansatz hab ich mal etwas zusammengedampft, nun mit Delimeterangabe:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function GetTreeNodePath2(aNode: TTreeNode; aDiv: String): String;
begin
  Result := '';
  while assigned(aNode) do
    begin
    Result := aDiv + IntToStr(aNode.Index) + Result;
    aNode := aNode.Parent;
    end;
  Delete(Result,1,Length(aDiv));
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
wazup
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 101

Windows XP
Delphi 2009
BeitragVerfasst: Fr 27.06.08 20:11 
-.- mal wieder nicht richtig geguckt :x
Bergmann89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Sa 28.06.08 01:04 
ahh,
Node.Parent da hät ich auch selber drauf kommen können :oops:
naja trotzdem vielen dank für die hilfe.

gn8