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 ??
Isn't this code a bit too simple??
-
- Newbie
- Posts: 21
- Joined: Mon Jan 23, 2006 12:00 am
Re: Isn't this code a bit too simple??
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 it wil provide the first node in the tree which contains 'TreeNode' inside it's text.
Regards,
Tom
If you use eg
Code: Select all
node := Tree1.Shapes.Find('TreeNode', true)
Regards,
Tom
-
- Newbie
- Posts: 21
- Joined: Mon Jan 23, 2006 12:00 am
Re: Isn't this code a bit too simple??
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.
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.