2013/9/11 Jürgen Hestermann <[email protected]> > On > http://wiki.freepascal.org/**VirtualTreeview_Example_for_**Lazarus<http://wiki.freepascal.org/VirtualTreeview_Example_for_Lazarus> > there is the following example procedure: > > ------------------------------**------------------ > procedure TForm1.Button1Click(Sender: TObject); > Var > Data: PTreeData; > XNode: PVirtualNode; > Rand: Integer; > Begin > Randomize; > Rand := Random(99); > XNode:=VST.AddChild(nil); > > if VST.AbsoluteIndex(XNode) > -1 then > Begin > Data := VST.GetNodeData(Xnode); > Data^.Column0:= 'One ' + IntToStr(Rand); > Data^.Column1:= 'Two ' + IntToStr(Rand + 10); > Data^.Column2:= 'Three ' + IntToStr(Rand - 10); > End; > End; > ------------------------------**------------------ > > Can someone explain what the line > > if VST.AbsoluteIndex(XNode) > -1 then > > actually means? > The method AbsoluteIndex gives back a Cardinal so how can it be less than > 0? > Therefore the if statement is completely useless because it is always true. > > BTW: I was pointed to this because Lazarus (or FPC?) showed me a compiling > message that this line will cause a type convertion to 64 bit (well done!). >
I didn't look at the code, but usually index = -1 means that the item was not found. So maybe AbsoluteIndex's result should actually be signed? In this example, I guess the test is to avoid a bug if AddChild does not manage to insert the root node. I don't know if AddChild could create a node without inserting, but this is what the code seems to be testing. -- Frederic Da Vitoria (davitof) Membre de l'April - « promouvoir et défendre le logiciel libre » - http://www.april.org
-- _______________________________________________ Lazarus mailing list [email protected] http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
