Solved

find a node in VST

Posted on 2016-09-09
2
63 Views
Last Modified: 2016-09-21
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.
0
Comment
Question by:dolphin King
  • 2
2 Comments
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 41792114
VST ?
Very Strong Tree ?
or a Virtually Silly Teacup ?
It helps in being explicit of what component  you use ...

don't like indenting ?
i use it to find memory leaks ...
never bothered about that ?
it also helps to make code more readable

Using SameText to search case insensitive

you got this code here: ?
http://www.delphipages.com/forum/showthread.php?t=152084

no point in checking for (Result = nil) in the while loop
That never happens

If you add the tree as a parameter, you can use this function from a common unit

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

Open in new window

0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 41792118
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

1

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 54
How to debug For loops? 3 45
listing all functions in JavaScript 19 177
silent install of security banner via msiexec command 4 74
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now