疑难杂症!似乎这个问题隐藏在我忽略的前瞻声明中.不知道偷偷摸摸的功能.
似乎编译器只考虑类的第一个声明来生成RTTI,所以如果你有这样的前向声明......
type TMyClass = class; ... ... {$METHODINFO ON} TMyClass = class private fField: integer; published property Field: integer read fField write fField; end; {$METHODINFO OFF} ... ... procedure TestRTTI; begin assert(assigned(GetPropInfo(TMyClass, 'Field')), 'WTF! No RTTI found!'); end;
...你会得到断言错误.因此,为了使RTTI正确,需要为正向声明启用{$ METHODINFO}指令,如此处所示....
type {$METHODINFO ON} TMyClass = class; {$METHODINFO OFF} ... ... TMyClass = class private fField: integer; published property Field: integer read fField write fField; end; ...