我试图像这样使用RTTI获取变量名.
这是我的测试.
type TStringHelper = record helper for string function Name: string; end; TMyRecord = record Field1:string; end; implementation { TStringHelper } function TStringHelper.Name: string; var context : TRttiContext; begin context := TRttiContext.Create; result := context.GetType(@Self).Name; // return empty context.Free; end; procedure TForm2.FormCreate(Sender: TObject); var r : TMyRecord; begin ShowMessage(r.Field1.Name); end;
TRttiType返回的名称为空.
有没有办法得到变量名?