I want to read fields of a record to a string list or an array of edit controls. My code is error, please fix it; and how to Write traversal the fields.
type
TItem = record
a : string[20];
b : word;
c : word;
end;
var
Form1: TForm1;
implementation
uses rtti;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
rttiContext: TRttiContext;
rttiType: TRttiType;
fields: TArray<TRttiField>;
item: TItem;
i:word;
begin
item.a:= hello ;
item.b:=123;
item.c:=456;
rttiType := rttiContext.GetType(TypeInfo(TItem));
fields := rttiType.GetFields;
for i := low(fields) to high(fields) do
begin
ShowMessage(fields[i].GetValue(@item).AsString);
end;
end;
end.