[fpc-pascal]TCollection question

Marco van de Voort marcov at stack.nl
Sun Jul 6 17:11:17 CEST 2003


> > IIRC, TCollection only stores TCollectionItem derived classes.
> > 
> > TList is closer to what you want probably.
> 
> Is there an example other than list.pp in the fcl source ?
> 
> Also just for the record of knowing... I have attached datanicks.pas
> which hold a dynamic array of TNick ... Is this what TList already does
> (if so I'm wasting my time writing my own code...) ?

Pretty much yes, but in a class wrapper. You can add and remove items,
iterate through them etc.  Maybe you can derive a class from TList to
customize it a bit.

There are two things to think of:
- you yourself have to make sure that elements are properly freed, so
   when deleting object A, get a reference to it, delete it from the list, 
   and then free the object. (however that can be automized in the class
   warpper)
- The internal list has two counters, instead of just "nNicks". One
   (capacity) is the reserved space, the other (count) is the amount of
   elements filled. This avoids too many memory fragmenting reallocs.
    (but that's better, not worse)

I learned to use the classes from code snippets written for  Delphi.

There is FCL documentation somewhere (and it will be in the next full 
release), but I couldn't find a recent version so fast.

So I put down a very old version (April 2002) on the web here:

www.stack.nl/~marcov/fcl.pdf

it at least describes the tlist methods.




More information about the fpc-pascal mailing list