我想在程序运行的时候知道一个结构体有哪几个成员,
并想对它作赋值操作。就象类一样,可以用ClassInfo来取。
{$M+}
type
R_Test = packed record
A : Integer;
B : Double;
end;
{$M-}
但是用TypeInfo(R_Test)时编译器告诉'R_Test' no Type info.
...全文
5020打赏收藏
关于RTTI,高人请进!伴水兄,chechy... 你们在吗?
我想在程序运行的时候知道一个结构体有哪几个成员, 并想对它作赋值操作。就象类一样,可以用ClassInfo来取。 {$M+} type R_Test = packed record A : Integer; B : Double; end; {$M-} 但是用TypeInfo(R_Test)时编译器告诉'R_Test' no Type info.
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节下的字段、属性、方法有效。