On 27/10/16 03:47, Graeme Geldenhuys wrote:
A common misconception about how interfaces work. In fact, I don't
actually know why FPC and Delphi bother with Interface Inheritance,
because I simply don't see the point.
To make your "t_2" class support both interface, you need to specify
both in the class declaration. Even though i_2 inherits from i_1, both
i_1 and i_2 must be specified in the t_2 class.

I must be missing something here because interface inheritance seems to work fine for me e.g.

i1 = interface
 procedure Do1;
end;

i2 = interface(i1)
 procedure Do2;
end;

TMyObject = class(TInterfacedObject,i2)
public
  procedure Do1;
  procedure Do2;
end;

var intf: i2;
begin
  i2 := TMyObject.Create;
  i2.Do1; {seems to work for me}
End;

I have plenty of examples where an interface is inherited and includes the inherited methods and properties.

I also have cases where e.g.

var SomeInterface: IUnknown;
begin
   SomeInterface := TMyObject.Create;
end;

that is the inherited interface is extracted from the object. There are also useful cases, where e.g.

TMyObject1 = class(TInterfacedObject,i1)
public
  procedure Do1;
end;

TMyObject2 = class(TMyObject1,i2)
public
  procedure Do2;
end;

That is you can build an object hierarchy to parallel an interface hierarchy.

I don't use the "Supports" primitive. - so maybe there is a bug in this feature but otherwise, what is the problem with interface inheritance?

Tony Whyman
MWA
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to