Folgende Klassen und Records habe ich (Code stark gekürzt):
Delphi-Quellcode:
TAcField = class
private
FFieldName : String;
FFieldValue : String;
public
constructor Create(AFieldName : String);
property FieldName : String read FFieldName;
property FieldValue : String read FFieldValue write FFieldValue;
end;
TAcArticle = record
Art_Desc : TAcField;
Art_Qty : TAcField;
end;
TAcArticleArray = Array[1..5] of TAcArticle;
TAc = class
private
FHeader : TAcField;
FVersion : TAcField;
FArticles : TAcArticleArray;
procedure FreeFields;
end;
procedure TAc.FreeFields;
type
PAcField = ^TAcField;
PAcArticleArray = ^TAcArticleArray;
var
LCtx : TRttiContext;
LField : TRttiField;
LArrayField : TRttiField;
pField : PAcField;
pArray : PAcArticleArray;
i : Integer;
begin
for LField in LCtx.GetType(Self.ClassInfo).GetDeclaredFields do
begin
if lfield.getvalue(self).Typeinfo.Name = 'TAcField' then
begin
pField := PAcField(NativeInt(Self) + lField.Offset);
TAcField(pField^).Free;
LField.SetValue(self, nil);
end;
if lfield.getvalue(self).Typeinfo.Name = 'TAcArticleArray' then
begin
pArray := PAcArticleArray(NativeInt(Self) + lField.Offset);
for i := Low(TAcArticleArray(pArray^)) to High(TAcArticleArray(pArray^)) do
begin
// das funktioniert zwar, aber möchte ich auch noch abstrahieren
// TAcArticleArray(pArray^)[i].Art_Desc.Free;
// TAcArticleArray(pArray^)[i].Art_Qty.Free;
// end;
// alle meine Versuche waren bislang ohne Erfolg:
for LArrayField in LCtx.GetType(????TAcArticleArray(pArray^)[i]????).AsRecord.GetFields do
begin
pField := PAcField(NativeInt(LArrayField) + LArrayField.Offset);
TAcField(pField^).Free;
LArrayField.SetValue(LArrayField, nil);
end;
end;
end;
end;
end;
Wie schaffe ich es alle Felder im Array freizugeben?