Link to home
Start Free TrialLog in
Avatar of dolphin King
dolphin King

asked on

find a node in VST

i am using this function to find node in treeview

function TFORM1.lookingTreeView(name: String): PVirtualNode;
var
Node: PVirtualNode;
Data: PUserData;
begin
Result := nil;
Node := VDT1.GetFirst;
while ((Node <> nil) and (Result = nil)) do
begin
Data := VDT1.GetNodeData(Node);
if (Data.FObject.name= name) then
begin
Result := Node;
break;
end
else
Node := VDT1.GetNext(Node);
end;
end;

Open in new window


and i use it like so
Node := lookingTreeView(namedata);

if Node <> nil then
begin
// then stop execute the code 
exit;
end;
// if its nil then do execute the rest of code

Open in new window


so this code search for node in Vst and if the node exits stop the code execution and if does not exits do the rest  

but some times this function got bypassed i mean when a node is already exits the if statement of node <> nil does not detect that its not nil and continue executing the code.
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
an exit in the middle of a procedure ?
why not reverse the logic ?

begin
  Node := lookingTreeView(namedata);
  if Node = nil then
  begin
    // if its nil then do execute the rest of code
  end;
end;

Open in new window