Delphi 2010 RTTI - RttiContext.FindType
使用 RttiContext.FindType('Classes.TStringList') 我可以毫无问题地获得 TStringList 的 RttiType 。但是使用 RttiContext.FindType('MyUnit.TMyClass') 我总是得到 nil (当然 MyUnit 在 use 子句中)。为什么,出了什么问题?
例子:
unit MyUnit;
interface
uses
Classes;
type
TMyClass = class(TStringList)
end;
implementation
end.
Main unit:
...
uses
MyUnit,
...
var
oCont: TRttiContext;
oType: TRttiType;
begin
oCont := TRttiContext.Create;
try
oType := oCont.FindType('MyUnit.TMyClass'); <== oType = nil !!
...
With RttiContext.FindType('Classes.TStringList')
I get RttiType of TStringList with no problem. But with RttiContext.FindType('MyUnit.TMyClass')
I always get nil (of course MyUnit is in uses clause). Why, what is wrong?
Example:
unit MyUnit;
interface
uses
Classes;
type
TMyClass = class(TStringList)
end;
implementation
end.
Main unit:
...
uses
MyUnit,
...
var
oCont: TRttiContext;
oType: TRttiType;
begin
oCont := TRttiContext.Create;
try
oType := oCont.FindType('MyUnit.TMyClass'); <== oType = nil !!
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能该类尚未被 delphi 链接器包含在最终的可执行文件中。快速尝试如下:
begin end
。TRttiContext.FindType
的类。Probably the class has not included by the delphi linker in the final executable. A fast try can be the following:
begin end
.TRttiContext.FindType
.这可能是一些事情。如果没有看到您的代码,很难说,但这里有一些值得一看的建议。 TMyClass 是接口部分中的公共类型吗?该设备的 RTTI 生成功能是否打开? MyUnit 是否位于尚未加载的包中?
It could be a handful of things. Hard to say without seeing your code, but here are a few suggestions to look at. Is TMyClass a public type in the interface section? Is RTTI generation turned on for that unit? Is MyUnit in a package that hasn't been loaded yet?