如何访问记录属性? [英] How to access record properties?
本文介绍了如何访问记录属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要访问,记录属性并设置/获取此属性值。
首先,我要访问属性。但是我不能。
I need to access, record properties, and set/get this property values. Firstly, i want to access properties. But i can't.
怎么了?
Ver:Delphi XE6。
What is wrong? Ver : Delphi XE6.
示例代码:
type
TmyRecord = record
private
Str : String;
public
property StrProp :String read Str;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
c : TRttiContext;
t : TRttiType;
field : TRttiField;
prop : TRttiProperty;
begin
c := TRttiContext.Create;
try
Memo1.Lines.Append('Fields');
for field in c.GetType(TypeInfo(TMyRecord)).GetFields do
begin
t := field.FieldType;
Memo1.Lines.Append('Field:'+field.Name);
Memo1.Lines.Append('RttiType:'+t.ClassName);
end;
Memo1.Lines.Append('Properties');
for prop in c.GetType(TypeInfo(TMyRecord)).GetProperties do
begin
t := prop.PropertyType;
Memo1.Lines.Append('Property:'+prop.Name);
Memo1.Lines.Append('RttiType:'+t.ClassName);
end;
finally
c.Free
end;
end;
推荐答案
您的问题是没有可供记录的RTTI属性已在2009年报告,但仍未修复( QC#78110 )。
Your problem is that there is no RTTI available for record properties as already reported in 2009 but still not fixed (QC#78110).
编辑:并且在2017年仍未修复( RSP-19303 )。
And still not fixed in 2017 (RSP-19303).
这篇关于如何访问记录属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文