[fpc-pascal] Re: Objects in dynamic arrays
Martin
lazarus at mfriebe.de
Sat Nov 16 02:36:08 CET 2013
On 16/11/2013 01:03, Timothy Groves wrote:
>
> 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];
Objects are actually stored via a reference (internal pointer)
So t_volumes [last] just points to the objects data
The above statement duplicates the reference
> t_volumes [last].Destroy;
destroys the object pointed to by both: t_volumes [last] and t_volumes
[index]
You should have destroyed t_volumes [index] *before* copying the value
More information about the fpc-pascal
mailing list