Hi Sergio,
until you are ready we use this workaround:
uses
System.Rtti,
System.SysUtils,
System.TypInfo,
sgcHTTP_OpenAPI_Client;
procedure sgcReleaseMembers(const AObject: TsgcOpenAPIClass);
implementation
var
Ctx: TRttiContext;
procedure sgcReleaseMembers(const AObject: TsgcOpenAPIClass);
type
TObjectArray = TArray<TObject>;
PObjectArray = ^TObjectArray;
var
LType: TRttiType;
LProp: TRttiProperty;
begin
LType:=Ctx.GetType(AObject.ClassType);
for LProp in LType.GetProperties do
begin
case LProp.PropertyType.TypeKind of
tkClass:
begin
if not LProp.IsWritable then Continue;
var PropValue:=LProp.GetValue(AObject);
var PropObj:=PropValue.AsObject;
if Assigned(PropObj) then
begin
if PropObj is TsgcOpenAPIClass
then sgcReleaseMembers(TsgcOpenAPIClass(PropObj));
PropObj.Free;
LProp.SetValue(AObject,nil);
end;
end;
tkDynArray:
begin
var CheckType:=Ctx.GetType(LProp.PropertyType.Handle);
if CheckType is TRttiDynamicArrayType then
begin
var ArrType:=TRttiDynamicArrayType(CheckType);
if ArrType.ElementType.TypeKind = tkClass then
begin
var ArrProperty:=LProp.GetValue(AObject);
var ObjArray:=PObjectArray(ArrProperty.GetReferenceToRawData);
if not Assigned(ObjArray) then Continue;
for var cc := 0 to Length(ObjArray^) - 1 do
begin
if Assigned(ObjArray^[cc]) and (ObjArray^[cc] is TsgcOpenAPIClass)
then sgcReleaseMembers(TsgcOpenAPIClass(ObjArray^[cc]));
ObjArray^[cc].Free;
ObjArray^[cc]:=nil;
end;
end;
end;
end;
end;
end;
end;
initialization
Ctx := TRttiContext.Create;
end.
Before a Instance.Free, we call sgcReleaseMembers(Instance).
You can use it for your solution, completely or partially.