Das sollte so eigentlich gehen...
Delphi-Quellcode:
function DeleteCount(Text:string):string;
var Posi:integer;
begin
Result:=Text;
repeat
Posi:=pos(' (', Text);
if Posi > 0 then
delete(Text, 1, Posi);
until Posi = 0;
delete(Result, length(Result) - length(Text), length(Result));
end;
function addChildCount(Node:TTreeNode):integer;
begin
Result:=0;
if assigned(Node) then begin
repeat
if Node.HasChildren then
Node.Text:=DeleteCount(Node.Text) + ' (' + inttostr(addChildCount(Node.getFirstChild)) + ')';
inc(Result);
Node:=Node.getNextSibling;
until not assigned(Node);
end;
end;
Aufruf:
addChildCount(TreeView.Items.GetFirstNode);