Delphi 帮助文档里提到RTTI{$M+}时说, The $M switch directive controls generation of runtime type information (RTTI). When a class is declared in the {$M+} state, or is derived from a class that was declared in the {$M+} state, the compiler generates runtime type information for fields, methods, and properties that are declared in a published section. 也就是说,RTTI只对类的Published节下的字段、属性、方法有效。你可以把你的记录定义改成类定义,再用{$M+},应该就OK了。
记录类型没有RTTI的证据: type R_Test = packed record higklmn222 : Integer; end; TMyClass = class(TComponent) Fabcdefg: Integer; published property abcdefg111: Integer read Fabcdefg write Fabcdefg; end; 在生成的EXE文件中可以找到'abcdefg111'这个字符串(用ultraedit之类的工具打开),但是没有'higklmn222'!即使使用$M+,RTTI中好像也只能访问published的内容,而不能访问其它的成员.
type
TMyClass = class(TComponent)
private
FRect: TRect;
FCount:Integer;
published
property Rect: TRect read FRect write FRect;
property Count: Integer read FCount write FCount;
end;//在Object Inspector看不见Rect
The $M switch directive controls generation of runtime type information (RTTI). When a class is declared in the {$M+} state, or is derived from a class that was declared in the {$M+} state, the compiler generates runtime type information for fields, methods, and properties that are declared in a published section.
也就是说,RTTI只对类的Published节下的字段、属性、方法有效。你可以把你的记录定义改成类定义,再用{$M+},应该就OK了。
type
R_Test = packed record
higklmn222 : Integer;
end;
TMyClass = class(TComponent)
Fabcdefg: Integer;
published
property abcdefg111: Integer read Fabcdefg write Fabcdefg;
end;
在生成的EXE文件中可以找到'abcdefg111'这个字符串(用ultraedit之类的工具打开),但是没有'higklmn222'!即使使用$M+,RTTI中好像也只能访问published的内容,而不能访问其它的成员.
但个人觉得应该将记录定义改成类定义后才有可能满足你的要求。
因为RTTI是专为类而设计的。参看了一些这方面的书籍后。发现它实际上是在存储类的信息时将RTTI的相关信息一起存进去了。在Borland的机制中好像是放在存在虚函数地方的前面。包含了类名,父亲名等相关信息。而存储记录不使用这种方法。所以赞成用: skyweb2k(skyweb) 的解决方法。