« Reply #4 on: May 26, 2021, 11:51:49 am »
Yepp. Works.
program Project1;
{$modeswitch advancedrecords}
Uses
SysUtils, Classes;
Type
{ TMyType }
TMyType = record
abc : Integer;
def : TStringList;
class operator initialize(var ARec:TMyType);
class operator finalize(var ARec:TMytype);
end;
Var
MyArray : array of TMyType;
i:Integer;
{ TMyType }
class operator TMyType.initialize(var ARec: TMyType);
begin
ARec.def:=TStringList.Create;
Writeln('Create StringList');
end;
class operator TMyType.finalize(var ARec: TMytype);
begin
ARec.def.Free;
WriteLn('Free StringList');
end;
begin
SetLength(MyArray,5);
For i:=0 To High(MyArray) Do MyArray[i].abc:=i;
SetLength(MyArray,0);
end.
HeapTrc throws no memory-leak
Returns in console.
Create StringList
Create StringList
Create StringList
Create StringList
Create StringList
Free StringList
Free StringList
Free StringList
Free StringList
Free StringList
Logged
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad