uses System.Rtti;
type
TPhone = class
public
Model: string;
end;
var
Ctx: TRttiContext;
Phone: TPhone;
Value: TValue;
begin
Phone := TPhone.Create;
Phone.Model := 'iPhone X';
//dynamic access by field name via RTTI
Value := Ctx.GetType(TPhone)
.GetField('Model').GetValue(Phone);
WriteLn('model is ', Value.AsString);
//model is iPhone X
Phone.Model := 'iPhone X 256';
Value := Ctx.GetType(TPhone)
.GetField('Model').GetValue(Phone);
WriteLn('model is ', Value.AsString);
//model is iPhone X 256
end.