[fpc-pascal] Arrays of objects
memsom at interalpha.co.uk
Wed Oct 31 12:27:14 CET 2007
Marco van de Voort wrote:
>> Adrian Maier wrote:
>> VArray: array of TSomeClass;
>> SetLength(VArray, 10);
>> // now you have VArray .. VArray;
>> SetLength(VArray, 20);
>> // now you have  .. ;
>> // Length(VArray) = 20
>> // for I := 0 to Pred(Length(VArray)) is a valid statement
>> They are reference counted, just like ansi strings, ie don't worry about
>> memory leakages.
> ... Of the array itself. The objects it contains is another matter.
Which is why TObjectList is a good choice: TObjectList.Create(True)
makes all instances added to the list owned by the list and free'd when
the list is free'd. TObjectList also manages the allocation/deallocation
and size for you.
More information about the fpc-pascal