记录中的Delphi RTTI访问阵列
我想列举记录的字段信息(名称,类型,...)。 RTTI提供字段名称,但键入为null(nil)!如何获取此信息?
记录:
foo = record
bar : array[0..5] of char;
end;
枚举:
for var f : TRttiField in TRTTIContext.Create.GetType(TypeInfo(foo)).GetFields do
begin
OutputDebugString(PWideChar(f.Name + ' :: ' + f.FieldType.ToString())); ///fieldtype is nil??!
end;
I want to enumerate field information (name, type, …) of a record. RTTI delivers field name but type is null(nil)! How can I get this information?
Record:
foo = record
bar : array[0..5] of char;
end;
Enumeration:
for var f : TRttiField in TRTTIContext.Create.GetType(TypeInfo(foo)).GetFields do
begin
OutputDebugString(PWideChar(f.Name + ' :: ' + f.FieldType.ToString())); ///fieldtype is nil??!
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据Delphi的文档:
Per Delphi's documentation:
Querying for Type Information
RTTI系统仅适用于预定义的类型。定义字段类型“即时”不会生成RTTI信息。因此,请声明这样的数组类型:
您将获得更多信息:
The RTTI system only works with predefined types. Defining field types "on-the-fly" does not generate RTTI information. So, declare the array type like this instead:
And you will get some more info: