Isn't this code a bit too simple??

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
achristouio
Newbie
Newbie
Posts: 21
Joined: Mon Jan 23, 2006 12:00 am

Isn't this code a bit too simple??

Post by achristouio » Mon May 11, 2009 4:39 pm

Since I didn't get a hit searching for a sentence I know is present in the tree I looked at the find-code:

Function TNodeShapeList.Find(Const S:String; Partial:Boolean=False):TTreeNodeShape;
var t : Integer;
begin
for t:=0 to Count-1 do
if ((not Partial) and (Items[t].SimpleText=S)) or
((Partial) and (Pos(S,Items[t].SimpleText)>0)) then
begin
result:=Items[t];
exit;
end;
result:=nil;
end;


Shouldn't there be a folding of each side of the here, either to lower case or to upper case.

The code above do only work if you ahead know the exact folding

Maybe some other compare function also could be used ??

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Re: Isn't this code a bit too simple??

Post by tom » Thu Jun 18, 2009 9:01 pm

There is no need for interating through each branch, as all shapes are also available through the shapes property of TTree.
If you use eg

Code: Select all

node := Tree1.Shapes.Find('TreeNode', true)
it wil provide the first node in the tree which contains 'TreeNode' inside it's text.

Regards,
Tom

achristouio
Newbie
Newbie
Posts: 21
Joined: Mon Jan 23, 2006 12:00 am

Re: Isn't this code a bit too simple??

Post by achristouio » Thu Jun 18, 2009 9:30 pm

Well, the code is not an example, but the implementation of find in the tree.pas file.

My comment was not about the iteration, but the fact that you only get a match if the sentence you enter is identical in folding to the text stored in the tree. Eg. if the node contain the text node1, and you search for 'Node1' you will never get a hit :-)

So I changed my local copy to contain a folding to the same case on both side of the comparison. :-)

Post Reply