Das Zauberwort heißt Rekursion...
Delphi-Quellcode:
procedure GetChilds(Node:TTreeNode; NodeList:TList);
var Child:TTreeNode;
begin
if assigned(Node) then begin
if Node.HasChildren then begin
Child:=Node.getFirstChild;
repeat
GetChilds(Child, NodeList);
Child:=Child.getNextSibling;
until not assigned(Child);
end
else NodeList.Add(Node);
end;
end;
Aufruf...
Delphi-Quellcode:
procedure TForm.ButtonClick(Sender: TObject);
var List:TList;
i:integer;
begin
List:=TList.Create;
try
GetChilds(TreeView.Items.GetFirstNode, List);
Memo.Lines.Clear;
for i:=1 to List.Count do
Memo.Lines.Append(TTreeNode(List[i-1]).Text);
finally
List.free;
end;
end;
Edit:
Oh, es geht ja nur um den Inhalt...
Delphi-Quellcode:
procedure GetChilds(Node:TTreeNode; List:TStrings);
var Child:TTreeNode;
begin
if assigned(Node) then begin
if Node.HasChildren then begin
Child:=Node.getFirstChild;
repeat
GetChilds(Child, List);
Child:=Child.getNextSibling;
until not assigned(Child);
end
else List.Append(Node.Text);
end;
end;
Aufruf...
Delphi-Quellcode:
procedure TForm.ButtonClick(Sender: TObject);
begin
GetChilds(TreeView.Items.GetFirstNode, Memo.Lines);
end;