[fpc-pascal] Re: Objects in dynamic arrays

Timothy Groves the.tail.kinker at gmail.com
Sat Nov 16 02:03:19 CET 2013


On 13-11-15 07:57 PM, Timothy Groves wrote:
> How exactly are instantiated classes treated in an array?  Can I copy 
> one into another?  And if I unallocate an array member, does it 
> automatically Destroy the object?
>
> I have objects stored in a dynamic array, and I want to delete an 
> arbitrary record.  What I have right now is:
>
> <snip incorrectly pasted code>
>
> 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;




More information about the fpc-pascal mailing list