[fpc-pascal] Arrays of objects
Lourival Mendes
mendes.lourival at gmail.com
Wed Oct 31 12:59:56 CET 2007
Dear Joao,
I do beleive that the SetLength only resize the array, ie: The
Vetor has 3 elements like:
Vetor[0]:= 1
Vetor[1]:= 2
Vetor[2]:= 3
And then eu want the same variable but with only 2 element, then
SetLength(Vetor, 2)
Vetor[0]:= 1
Vetor[1]:= 2
As you can see you don't lose the first 2, After that you want 4
elements on the same variable:
SetLength(Vetor, 4)
If you print the variable, before associate any value to it you will get:
Vetor[0]:= 1
Vetor[1]:= 2
Vetor[2]:= 0
Vetor[3]:= 0
Hope it helped
Lourival
2007/10/31, Joao Morais <post at joaomorais.com.br>:
> Marco van de Voort wrote:
> >> Adrian Maier wrote:
> >> VArray: array of TSomeClass;
> >> begin
> >> SetLength(VArray, 10);
> >> // now you have VArray[0] .. VArray[9];
> >> SetLength(VArray, 20);
> >> // now you have [0] .. [19];
> >> // 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.
>
> Ah, yes, forgot to mention this. I usually use dyn arrays to manage
> objects owned by other lists or objects.
>
> --
> Joao Morais
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
--
Lourival J. Mendes Neto
More information about the fpc-pascal
mailing list