Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
Delphi 10.2 Tokyo Professional
|
AW: Delphi Record in for-schleife
10. Jan 2020, 16:18
Kurz zusammengebastelt:
Delphi-Quellcode:
uses
System.RTTI;
type
TTestRecord = record
Test1: String[10];
Test2: String[20];
Test3: String[50];
Test4: String[50];
End;
procedure TForm1.FormCreate(Sender: TObject);
var testRec: TTestRecord;
rtti: TRttiContext;
typ: TRttiType;
field: TRttiField;
recAsString: AnsiString;
begin
testRec.Test1 := ' Hallo';
testRec.Test2 := ' Welt';
testRec.Test3 := ' und';
testRec.Test4 := ' so';
rtti := TRttiContext.Create;
try
typ := rtti.GetType(TypeInfo(TTestRecord));
recAsString:= ' ';
for field in typ.GetFields() do
recAsString := recAsString + PShortString(NativeUInt(@testRec) + NativeUInt(field.Offset))^;
ShowMessage( String(recAsString));
finally
rtti.Free;
end;
end;
Dafür muss dein Record aber zu 100% aus ShortStrings bestehen.
Michael "Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
|