<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2013/9/11 Jürgen Hestermann <span dir="ltr"><<a href="mailto:juergen.hestermann@gmx.de" target="_blank">juergen.hestermann@gmx.de</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On<br>
<a href="http://wiki.freepascal.org/VirtualTreeview_Example_for_Lazarus" target="_blank">http://wiki.freepascal.org/<u></u>VirtualTreeview_Example_for_<u></u>Lazarus</a><br>
there is the following example procedure:<br>
<br>
------------------------------<u></u>------------------<br>
procedure TForm1.Button1Click(Sender: TObject);<br>
Var<br>
Data: PTreeData;<br>
XNode: PVirtualNode;<br>
Rand: Integer;<br>
Begin<br>
Randomize;<br>
Rand := Random(99);<br>
XNode:=VST.AddChild(nil);<br>
<br>
if VST.AbsoluteIndex(XNode) > -1 then<br>
Begin<br>
Data := VST.GetNodeData(Xnode);<br>
Data^.Column0:= 'One ' + IntToStr(Rand);<br>
Data^.Column1:= 'Two ' + IntToStr(Rand + 10);<br>
Data^.Column2:= 'Three ' + IntToStr(Rand - 10);<br>
End;<br>
End;<br>
------------------------------<u></u>------------------<br>
<br>
Can someone explain what the line<br>
<br>
if VST.AbsoluteIndex(XNode) > -1 then<br>
<br>
actually means?<br>
The method AbsoluteIndex gives back a Cardinal so how can it be less than 0?<br>
Therefore the if statement is completely useless because it is always true.<br>
<br>
BTW: I was pointed to this because Lazarus (or FPC?) showed me a compiling<br>
message that this line will cause a type convertion to 64 bit (well done!).<br>
</blockquote></div><br></div><div class="gmail_extra">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.<br clear="all">
</div><div class="gmail_extra"><br>-- <br>Frederic Da Vitoria<br>(davitof)<br><br>Membre de l'April - « promouvoir et défendre le logiciel libre » - <a href="http://www.april.org" target="_blank">http://www.april.org</a><br>
</div></div>