hulig4n
14 years agoNew Contributor
how to loop through all nodes of a TreeView
Hi!
Im trying to loop through all nodes of a TreeView. I know how to do that in Delphi (with recursion), but I can't manage this in TestComplete. Here is what I have done so far:
1. Made a simple delphi application containing only one form with a TreeView on it (containg about 200 nodes).
2. Made a keyword test that opens the application and clicks on one node, then closes the app.
3. Wrote a script (Delphi) that should go throught all nodes and click every one, but i only manage to go through one level of the tree (the first one).
Here is the code of the script:
procedure Main;
var
r: OleVariant;
i: integer;
begin
r:= NameMapping.Sys.Project1.Form1.tvPrintReport; //treeview
if r.Exists then
begin
for i:= 0 to r.wRootItemCount-1 do //this is only the first level
if r.wItems.Item(i).Items.Count > 0 then
SubTree(r.wItems.Item(i)); //trying to use recursive procedure SubTree, but this wont compile
//ShowMessage(inttostr(r.wItems.Item(i).Items.Count));
end;
end;
procedure SubTree(ANode: OleVariant);
var
i: integer;
begin
if ANode.Items.Count > 0 then
begin
for i:= 0 to ANode.Items.Count-1 do
SubTree(ANode.Items.Item(i));
end
else
ANode.Click;
end;
Can anyone tell me how to properly loop through all nodes?
Thanks in advance.
Im trying to loop through all nodes of a TreeView. I know how to do that in Delphi (with recursion), but I can't manage this in TestComplete. Here is what I have done so far:
1. Made a simple delphi application containing only one form with a TreeView on it (containg about 200 nodes).
2. Made a keyword test that opens the application and clicks on one node, then closes the app.
3. Wrote a script (Delphi) that should go throught all nodes and click every one, but i only manage to go through one level of the tree (the first one).
Here is the code of the script:
procedure Main;
var
r: OleVariant;
i: integer;
begin
r:= NameMapping.Sys.Project1.Form1.tvPrintReport; //treeview
if r.Exists then
begin
for i:= 0 to r.wRootItemCount-1 do //this is only the first level
if r.wItems.Item(i).Items.Count > 0 then
SubTree(r.wItems.Item(i)); //trying to use recursive procedure SubTree, but this wont compile
//ShowMessage(inttostr(r.wItems.Item(i).Items.Count));
end;
end;
procedure SubTree(ANode: OleVariant);
var
i: integer;
begin
if ANode.Items.Count > 0 then
begin
for i:= 0 to ANode.Items.Count-1 do
SubTree(ANode.Items.Item(i));
end
else
ANode.Click;
end;
Can anyone tell me how to properly loop through all nodes?
Thanks in advance.