我想使用D2010 RTTI获取接口。德尔福RTTI无法找到接口
program rtti_sb_1;
{$APPTYPE CONSOLE}
{$M+}
uses
SysUtils,
Rtti,
mynamespace in 'mynamespace.pas';
var
ctx: TRttiContext;
RType: TRttiType;
MyClass: TMyIntfClass;
begin
ctx := TRttiContext.Create;
MyClass := TMyIntfClass.Create;
// This prints a list of all known types, including some interfaces.
// Unfortunately, IMyPrettyLittleInterface doesn't seem to be one of them.
for RType in ctx.GetTypes do
WriteLn(RType.Name);
// Finding the class implementing the interface is easy.
RType := ctx.FindType('mynamespace.TMyIntfClass');
// Finding the interface itself is not.
RType := ctx.FindType('mynamespace.IMyPrettyLittleInterface');
MyClass.Free;
ReadLn;
end.
两个IMyPrettyLittleInterface
和TMyIntfClass = class(TInterfacedObject, IMyPrettyLittleInterface)
在mynamespace.pas
声明,尤其是
unit mynamespace;
interface
type
IMyPrettyLittleInterface = interface
['{6F89487E-5BB7-42FC-A760-38DA2329E0C5}']
end;
TMyIntfClass = class(TInterfacedObject, IMyPrettyLittleInterface)
end;
//...
千万人知道为什么不起作用?有没有办法解决我的问题?提前致谢!
嗨,罗伯特!谢谢你的回答 - 它的效果非常好!这似乎很奇怪,但。目前,我会采取一种解决方法,但我确信希望它在未来能够得到解决。你认为我应该向QC报告? – conciliator 2010-06-08 16:43:39
是的,我认为它应该被QC'ed。 – 2010-06-08 19:53:49
完成。现在报告为QC#85277。 – conciliator 2010-06-09 06:26:58