delphi - FireMonkey 在运行时使用 RTTI 获取 FMXObjects

标签 delphi rtti

我正在尝试获取(使用RTTI)我的应用程序中的表单,以便在运行时创建它们,基于表单Name

我已经声明了 {$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.TFormTPercient 后代,它是使用 {$M+} 指令编译的,其中是 {$TYPEINFO ON} 的别名。因此,您无需启用它即可访问 TForm RTTI

关于delphi - FireMonkey 在运行时使用 RTTI 获取 FMXObjects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40208224/

相关文章:

德尔福 SOAP : delete temporary file after response dispatched

delphi - 访问嵌入式 TFrame 中的组件属性

c++ - 从 String 到 Type (C++) 的最佳方法是什么

Delphi 类帮助器 RTTI GetMethod

delphi - 如何使用 tFDMemTable 将多个数据表保存到一个文件

delphi - 在 Delphi 中 Hook DLL 函数

delphi - 如何从 TRttiType 实例化一个类?

c++ - 没有 RTTI 的 dynamic_cast

delphi - 如何检查某项是否支持通用接口(interface)?

delphi - 重载函数参数的类型提升