[Lazarus] VirtualTreeView, Absoluteindex example on freepascal.org

Frederic Da Vitoria davitofrg at gmail.com
Thu Sep 12 23:13:08 CEST 2013


2013/9/12 Jürgen Hestermann <juergen.hestermann at gmx.de>

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


No, I am not sure, as I stated in my first answer, I am answering from
memory, all my answers here are mainly guesses. Either my first assumption
is right or maybe whoever wrote the the button code example thought that
VirtualTreeview behaved like IndexOf (which is what I would have expected
too).

If you are interested, I still have an old version from 2001 on a backup ,
I could check it.


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


Well then, I can add a variant to my first option: create the functionality
(since IMO it should be there).


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


In the current state of the code, I agree it is useless.

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130912/21f42479/attachment-0003.html>


More information about the Lazarus mailing list