Hello guys

Hello guys,

Is there a way to a interface inherit from many other interfaces? For example:
public interface UserMethods {
}
public interface WallMethods {
}
public interface OpenreduAPI : UserMethods, WallMethods {
}

I can do this using C# and Java, but I was not able to achieve something similar with Delphi :(
I tried this:
IUserMethods = interface
end;
IWallMethods = interface
end;
IOpenreduAPI = interface(IUserMethods, IWallMethods)
end;

But it doesn't compile, multiple interface inheritance is very useful for compose REST API calls :D

Many thanks :D

Comments

  1. No you can not do this, but when implementing a class it can implement multiple interfaces

    ReplyDelete
  2. Yes, multiple interface inheritance is a nice feature. But it has never been developed for the Delphi compiler.

    ReplyDelete
  3. perhaps with includes

    type
      IUserMethods = interface
      {$INCLUDE userMethods.inc}
      end;
      IWallMethods = interface
      {$INCLUDE userMethods.inc}
      {$INCLUDE WallMethods.inc}
      end;
      IOpenreduAPI = interface
      {$INCLUDE userMethods.inc}
      {$INCLUDE WallMethods.inc}
      {$INCLUDE OpenreduAPI.inc}
      end;

    but you still have to specify the 3 interfaces if you want to query them

     TMyClass = class(TInterfacedObject, IUserMethods, IWallMethods, IOpenreduAPI)
     end;

    ReplyDelete
  4. NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!

    ReplyDelete
  5. Paul TOTH your example does not need this ugly hack. you can simply do:

    IUserMethods = interface;

    IWallMethods = interface(IUserMethods);

    IOpenreduApi = interface(IWallMethods)

    ReplyDelete
  6. oups, too early before coffee :/

    type
      IUserMethods = interface
      {$INCLUDE userMethods.inc}
      end;
      IWallMethods = interface
     /////// {$INCLUDE userMethods.inc}
      {$INCLUDE WallMethods.inc}
      end;
      IOpenreduAPI = interface
      {$INCLUDE userMethods.inc}
      {$INCLUDE WallMethods.inc}
      {$INCLUDE OpenreduAPI.inc}
      end;

    ReplyDelete
  7. A bit of history why Delphi does not have it (the last paragraph): http://edn.embarcadero.com/article/29779

    ReplyDelete
  8. Indeed Stefan Glienke is right: because COM heritage.  Too bad they still cannot cut themselves loose from that.

    ReplyDelete

Post a Comment