As starting point - record with simple types. For complex fields (array, class etc) explore RTTI unit
type
TmyRecord = record
aValue: String;
aNumber: Real;
Morenumbers: Integer;
end;
var
m: TMyRecord;
rtype: TRTTIType;
fields: TArray<TRttiField>;
i: Integer;
begin
m.aValue := 'OK';
m.aNumber := Pi;
m.Morenumbers := 666;
rtype := TRTTIContext.Create.GetType(TypeInfo(TMyrecord));
Memo1.Lines.Add(rtype.ToString);
fields := rtype.GetFields;
for i := 0 to High(fields) do
Memo1.Lines.Add(Format('%s: %s :: %s', [
fields[i].Name,
fields[i].FieldType.ToString,
fields[i].GetValue(@m).ToString]));
output:
TmyRecord
aValue: string :: OK
aNumber: Real :: 3.14159265358979
Morenumbers: Integer :: 666
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…