[fpc-pascal] Question about System.Move()

Sven Barth pascaldragon at googlemail.com
Sun Jan 10 12:05:48 CET 2021


Am 09.01.2021 um 22:54 schrieb Bart via fpc-pascal:
> On Sat, Jan 9, 2021 at 8:14 PM Yuriy Sydorov via fpc-pascal
> <fpc-pascal at lists.freepascal.org> wrote:
>
>>> So, I'll use a for loop to copy the data.
>>>
>>> I assume that doing Arr[Index] := Default(T) will also finalize the
>>> element if that element ismanaged?
>> For class object instances call Arr[Index].Free, for other managed types or records containing managed types
>> Finalize(Arr[Index]) should work.
> In the base class, is there a way to check wether Arr[Index] is an
> object instance or a managed type or a datatype containing a managed
> type?

If by "base class" you mean the generic class (and not a base class in 
the object hierarchy sense), then you can use the IsManagedType 
intrinsic which is available since 3.2.0.

> Now the for loop (I abandoned the use of Move) does something like this:
>    Arr[NewIndex] := Arr[OldIndex];  //do I have to finalize/free
> Arr[NewIndex] also in this case?
No, the compiler will handle that correctly (it's just a normal 
assignment after all).

>    Arr[OldIndex] := Default(T);  //I understand this is not enough in those cases
This is only not enough for class instances if they should be Free'd. 
For everything else this is indeed enough.

Regards,
Sven


More information about the fpc-pascal mailing list