Search code examples
delphiinheritanceinterfacemultiple-inheritance

Multiple inheritance for interfaces


Is there a way to define an interface who inherits from two or more interfaces?

I tried the following code on Delphi2007:

  IInterfaceA = interface
     procedure A;
  end;

  IInterfaceB = interface
    procedure B;
  end;

  IInterfaceAB = interface(IInterfaceA, IInterfaceB);

.. and it raised an E2029 error:

E2029 ')' expected but ',' found

at line:

IInterfaceAB = interface(IInterfaceA, IInterfaceB).


Solution

  • There is no multiple interface inheritance in Delphi as there is no multiple inheritance in Delphi at all. All you can do is make a class implement more than one interface at once.

    TMyClass = class(TInterfacedObject, IInterfaceA, IInterfaceB)