[Lazarus] VirtualTreeView, Absoluteindex example on freepascal.org

Jürgen Hestermann juergen.hestermann at gmx.de
Thu Sep 12 19:53:08 CEST 2013


Am 2013-09-12 17:51, schrieb Frederic Da Vitoria:
 > My remarks only come from my memories of how VirtualTreeView worked with Delphi 6.
 > The code has obviously much changed since.

Are you sure? The function is quite simple:
---------------------------------------------------------------------
function TBaseVirtualTree.AbsoluteIndex(Node: PVirtualNode) : Cardinal;
begin
Result := 0;
while Assigned(Node) and (Node<>FRoot) do
    begin
    if not (vsInitialized in Node.States) then
       InitNode(Node);
    if Assigned(Node.PrevSibling) then
       begin // if there's a previous sibling then add its total count to the result
       Node := Node.PrevSibling;
       Inc(Result, Node.TotalCount);
       end
     else
       begin
       Node := Node.Parent;
       if Node<>FRoot then
          Inc(Result);
       end;
    end;
end;
---------------------------------------------------------------------
It's hard to believe that there was a version of VirtualTreeView
that used signed intergers *and* had code to set it to -1 *and*
then someone has changed it to a non-signed integer *and*
also removed or changed the code to now set it to zero.


 > I see 2 options: either restore the old functionality if needed

I don't believe that an "old functionality" exits.
It looks as if it was like that from the beginning.


 > If I read the code correctly,
 > if the parameter is the root, AbsoluteIndex will answer 0.
 > If the parameter is not found, AbsoluteIndex will answer 0 too.

Yes. There are 3 cases where the result is 0:
1.) Node is nil
2.) Node is the (invisible) root node
3.) Node is the first (visible) node

All of them result in zero so these cases cannot be
distinguished by the function result.


 > Is this deliberate?

That's the question.
But I don't think that it was different at any time.
And it seems that as long as this is not changed in VirtualTreeView
the if statement in the example on the Free Pascal page is nonsense.







More information about the Lazarus mailing list