Delphi RTTI unable to find interface

Posted by conciliator on Stack Overflow See other posts from Stack Overflow or by conciliator
Published on 2010-06-08T13:38:56Z Indexed on 2010/06/08 13:42 UTC
Read the original article Hit count: 287

Filed under:
|
|

I'm trying to fetch an interface using D2010 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.

Both IMyPrettyLittleInterface and TMyIntfClass = class(TInterfacedObject, IMyPrettyLittleInterface) are declared in mynamespace.pas. Do anyone know why this doesn't work? Is there a way to solve my problem? Thanks in advance!

© Stack Overflow or respective owner

Related posts about delphi

Related posts about interface