【发布时间】:2012-05-15 11:57:37
【问题描述】:
我正在尝试使用TRttiContext.FindType(QualifiedTypeName) 获取一个对象。这是我得到的:
program MissingRTTI;
{$APPTYPE CONSOLE}
uses System.SysUtils, RTTI, Classes;
type
TMyClass = class(TObject) end;
var
rCtx: TRttiContext;
rType: TRttiInstanceType;
begin
rCtx := TRttiContext.Create();
rType := rCtx.GetType(TypeInfo(TMyClass)) as TRttiInstanceType;
if (rType <> nil) then begin
WriteLn('Type found using TypeInfo');
end;
rType := rCtx.FindType(TMyClass.QualifiedClassName) as TRttiInstanceType;
if (rType <> nil) then begin
WriteLn('Type found using qualified class name.');
end;
ReadLn;
rCtx.Free();
end.
不幸的是,似乎只有rCtx.GetType 可以找到所需的类型。 (我也尝试使用 GetTypes 列出所有类型。所需的类型不会出现在结果数组中。)有人知道如何强制编译器为这种类型发出 RTTI 吗?
【问题讨论】:
标签: delphi delphi-xe2 rtti