[Lazarus] How to iterate through a TAvgLvlTree

Alexander Klenin klenin at gmail.com
Fri Mar 16 11:40:22 CET 2012


On Fri, Mar 16, 2012 at 21:36, Felipe Monteiro de Carvalho
<felipemonteiro.carvalho at gmail.com> wrote:
> Can I add a routine to access the AvgLvlTree as an array? To make it a
> better substitute to TFPList in objects which offer an indirect
> interface to the internal list, such as TLazAccessibleObject.
>
> My idea is defining:
> Index zero = Tree.FindLowest
> Indez Count-1= Tree.FindHighest
>
> On each access store the last accessed node and if the next call wants
> a node index=oldindex+1 or -1 then just use:
>
>  Tree.FindSuccessor(Node)
>  Tree.FindPrecessor(Node)
>
> Because almost always I use the array access only to iterate in a loop.

Ouch. This is exactly what enumerators are were designed to avoid.
Maybe convert TLazAccessibleObject to expect enumerable instead?

-- 
Alexander S. Klenin




More information about the Lazarus mailing list