Page 1 of 1

Isn't this code a bit too simple??

Posted: Mon May 11, 2009 4:39 pm
by 9345067
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;
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

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 ??

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

Posted: Thu Jun 18, 2009 9:01 pm
by Tom
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.


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

Posted: Thu Jun 18, 2009 9:30 pm
by 9345067
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. :-)