[fpc-pascal] Objects in dynamic arrays

Timothy Groves the.tail.kinker at gmail.com
Sat Nov 16 01:57:37 CET 2013


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:

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 (t_current_volume = t_volumes [index]) then
     t_volumes [index].Destroy;
   SetLength (t_volumes, last);
end;

This produces bad results, as it currently sits. What am I doing wrong?



More information about the fpc-pascal mailing list