使用派生接口时,接口委派不起作用

Bas*_*scy 2 delphi

在Delphi Seattle 10中,我试图使用implements关键字委托接口的实现,但是当从第一个接口派生的接口也包含在类声明中时,不接受委托.

以下代码的编译失败,并显示"缺少接口方法IInterface1.DoSomethingFor1的实现"消息.如果我从类声明中删除IInterface2,代码将编译.如果我从其他东西中导出IInterface2,那么它也会编译.

我究竟做错了什么?或者我怎样才能做到这一点?

type
  IInterface1 = interface(IInterface)
    ['{03FB3E2E-C0DD-4E17-B6CD-D333E1E7255E}']
    procedure DoSomethingFor1;
  end;

  Iinterface2 = interface(IInterface1)
    ['{89C266E2-2816-46AD-96AA-DD74E78A4D1E}']
  end;

  T1 = class(TInterfacedObject, IInterface1, IInterface2)
  private
    Fi1: IInterface1;
  public
    property I1_Delegate: IInterface1 read Fi1 implements IInterface1;
  end;
Run Code Online (Sandbox Code Playgroud)

Dav*_*nan 5

你需要明确地实现IInterface1IInterface2.你只实现前者.因此编译错误.你的实现类应该是这样的:

type
  TImplementingClass = class(TInterfacedObject, IInterface1, IInterface2)
  private
    Fi2: IInterface2;
  public
    property I2_Delegate: IInterface2 read Fi2 implements IInterface1, IInterface2;
  end;
Run Code Online (Sandbox Code Playgroud)