[fpc-devel] inheritance of interfaces.
Michael Van Canneyt
michael at freepascal.org
Mon Feb 2 17:35:27 CET 2026
On Mon, 2 Feb 2026, Martin Frb via fpc-devel wrote:
> 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.
More information about the fpc-devel
mailing list