Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2026-02

inheritance of interfaces.

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

If I have the below code, I can pass an object that has I1 (TFoo if uncommented) to the test function

I can also pass an inherited interface. "x1: i2"

But I can not pass a call that only has the inherited interface?  Error: Class "TFoo" does not implement interface "I1"

Is that intended?

Since TFoo implement I2, it does also implement I1.

program Project1;
{$Mode objfpc}
{$Interfaces CORBA}
type
   I1 = interface
     function Get1: byte;
   end;
   I2 = interface(I1)
     function Get2: byte;
   end;
   TFoo = class(TObject, I2)
   //TFoo = class(TObject, I2, I1)
     function Get1: byte; virtual; abstract;
     function Get2: byte; virtual; abstract;
   end;
   procedure test(a: I1);
   begin
   end;
var
x1: i2;
x2: TFoo;
begin
   test(x1);
   test(x2);
end.

Reply by email

Michael Van Canneyt
to Martin Frb
Martin Frb wrote 9 lines
If I have the below code, I can pass an object that has I1 (TFoo if uncommented) to the test function I can also pass an inherited interface. "x1: i2" But I can not pass a call that only has the inherited interface?  Error: Class "TFoo" does not implement interface "I1" Is that intended?

Yes

Since TFoo implement I2, it does also implement I1.

No. The inheritance is just a typing convenience.

When you do an "as interface", then the compiler looks for the UUID of the interface in a table.

If you define
TFoo = class(TObject, I2)
only the UUID of I2 is inserted in the table.

but if you define
TFoo = class(TObject, I1, I2)
then the table will contain both UUIDS and the "as I1" will work.

This is delphi compatible.

Michael.

Reply by email