遍历所有节点
给你一个只有一个根节点的例子,要是多个,稍微修改一下就好
function TForm1.FreeNode(Tree: TTreeView;
S: String): TTreeNode;
function _FreeNode(S: String;
Node: TTreeNode;OnFindCallBack: TOnFindCallBack): TTreeNode;
var
i: Integer;
tmp: TTreeNode;
begin
if not Assigned(Node) then
begin
Exit;
end
else
begin
if (Node.Text = S) then
begin
if Assigned(OnFindCallBack) then
OnFindCallBack(Node);
end;
tmp := Node.getFirstChild;
while tmp <> nil do
begin
_FreeNode(S,tmp,OnFindCallBack);
tmp := tmp.getNextSibling;
end;
end;
end;
begin
_FreeNode(S,Tree.Items.GetFirstNode,OnFound);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FreeNode(TreeView1,'1111');
end;
procedure TForm1.OnFound(Node: TTreeNode);
begin
Node.Selected := True;
showmessage('i got!');
end;