Yeah, I know I post a lot of questions, but thats because I either need assurance that I am doing it right, what I am doing wrong, or if I am totally clueless, and cant find anything in the documentation. Anyways,
I am trying to check for duplicate nodes. Here is how I would want to do it:
Loop thru my nodes, and compare each single node's text (record), but if I got many nodes, wouldnt that be too time and memory consuming? Would there be a better approach for this?
Thanks! - Jeff.
EDIT: Thanks to Deltics, I got it working! In case we have some people with the same question, here is some working code, using 2 levels of nodes in VST!
Procedure UncheckDuplicates;
Var
ParentNode,ChildNode : PVirtualNode;
I,J : Integer;
SL : TStringList;
SkypeID : String;
Begin
SL := TStringlist.Create;
try
ParentNode := frmMain.vtSkype.GetFirst;
for I := 0 to frmMain.vtSkype.RootNodeCount - 1 do
begin
ChildNode := ParentNode.FirstChild;
for J := 0 to ParentNode.ChildCount - 1 do
begin
if NodeIsChecked(ChildNode) then
begin
SkypeID := GetData(ChildNode).SkypeID;
if SL.IndexOf(SkypeID) <> -1 then
begin
ChildNode.CheckState := csUncheckedNormal;
end
else
begin
SL.Add(SkypeID);
end;
end;
ChildNode := ChildNode.NextSibling;
end;
ParentNode := ParentNode.NextSibling;
end;
finally
SL.Free;
end;
frmMain.vtSkype.Refresh;
End;
I am not afraid to share my code, I owe it to the community. :)
RootNodeCount
orChildCount
to make the control create nodes for all your items. The tree control should not be where you store your program's data. It's just a view of the data. – IngamarPVirtualNode
at all. (And besides that, you should really use theGetNextSibling
method instead of directly reading theNextSibling
field; the method ensures the node you get has been properly initialized.) – Ingamar