Delphi interface inheritance: Why can't I access ancestor interface's members?

前端 未结 4 1175
温柔的废话
温柔的废话 2020-12-06 17:43

Assume you have the following:

//Note the original example I posted didn\'t reproduce the problem so
//I created an clean example  
  type
    IParent = inte         


        
4条回答
  •  旧巷少年郎
    2020-12-06 18:03

    edit: This answer is no longer relevant because it was posted before the original question got modified.


    This compiles in Delphi 2010:

    type
      IParent = interface(IInterface)
        function DoSomething: String;
      end;
    
      IChild = interface(IParent)
        function DoSomethingElse: string;
      end;
    
      TMyClass = class(TInterfacedObject, IChild)
      private
      public
        function DoSomething: String;
        function DoSomethingElse: String;
      end;
    
    // ... 
    
    procedure Test;
    var
      MyObject : IChild;
    begin
      MyObject := TMyClass.Create;
      MyObject.DoSomething;
    end;
    

提交回复
热议问题