我正在尝试获取(使用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.TForm
是 TPercient
后代,它是使用 {$M+
} 指令编译的,其中是 {$TYPEINFO ON}
的别名。因此,您无需启用它即可访问 TForm
RTTI
关于delphi - FireMonkey 在运行时使用 RTTI 获取 FMXObjects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40208224/