我想使用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