[fpc-pascal] Re: Objects in dynamic arrays

Sven Barth pascaldragon at googlemail.com
Sat Nov 16 10:25:36 CET 2013


On 16.11.2013 02:03, Timothy Groves wrote:
>> This produces bad results, as it currently sits. What am I doing wrong?
>
> Here's the code I *actually* have in the method:
>
> var
>    index,
>    last : integer;
> begin
>    last := length (t_volumes) - 1;
>    index := 0;
>    while ((t_volumes [index] <> t_current_volume) and (index < last)) do
>        inc (index);
>    if (index < last) then begin
>      t_volumes [index] := t_volumes [last];
>    t_volumes [last].Destroy;
>    end;
>    SetLength (t_volumes, last);
> end;

Martin already said the necessary points, but I'd like to say you a note 
not related to your problem: if you use "High(t_volumes)" you get the 
value of the highest index of the array, so you could replace your 
"last" with that. Just saying...

Regards,
Sven



More information about the fpc-pascal mailing list