[fpc-devel] interfaces / inheritance / again -x

Martin Frb lazarus at mfriebe.de
Mon Feb 2 22:28:43 CET 2026


On 02/02/2026 22:00, Michael Van Canneyt via fpc-devel wrote:
>
> Whether it is a good approach, there we probably differ in opinion :-)


Well, the good approach doesn't work.

interface can't have virtual/override apparently (it can but ignores).


In a class, an overridden function can actually return a subclass of 
what the virtual method returned.
And well, why not, it fulfills all the need.

If that was possible in an interface too, then all would be good

IFoo = interface
   function Itm: TItem; virtual;

ISubFoo = interface(IFoo)
   function Itm: TSubItem; override;

ISubFoo fulfils every bit of the contract of its base.
But this does not work, so I need to look for something else.


You read my description. Ideas?

Other than just "drop the constraint" => then yes, it works, because I 
have completely independent interfaces, no inheritance, just the same 
name for 2 functions that have diff return types....
I can't however see, how that is better.

Copy and paste the code... That might have been the solution before 
generics.

Not using interfaces at all => but this code includes (not limited but 
includes) stuff that is an API for 3rd party. Really want that as an 
interface.


More information about the fpc-devel mailing list