FireMonkey 在运行时使用 RTTI 获取 FMXObjects

FireMonkey Getting FMXObjects at runtime using RTTI

我正在尝试获取(使用 RTTI)我的应用程序中的 forms,以便根据 runtime 表格创建它们14=].

我已声明 {$TYPEINFO ON} 编译器指令并编码:

 lRttiType := pRttiContext.FindType ('Forms.tForm');

但我得到了 nil 结果。

'Forms.tForm' 应该是形式 Name?

我们将不胜感激。

正如 documentation 所说:

TRttiContext.FindType, which looks up the type information based on the qualified type name. The qualified type name is made up of two components: unit name, separated by the dot character from the type name (for example, Classes.TStrings).

Firemonkey 框架 TForm 的完整 QualifiedName 将是:FMX.Forms.TForm

请注意 QualifiedName 区分大小写。

lRttiType := pRttiContext.FindType ('FMX.Forms.TForm'); // this finds the TRttiType
lRttiType := pRttiContext.FindType ('fmx.forms.TForm'); // this will return nil

还要注意,FMX.Forms.TFormTPersistent 的后代,它是使用 {$M+} 指令编译的,它是 {$TYPEINFO ON} 的别名。因此,您无需启用它即可访问 TForm RTTI