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.
_______________________________________________
fpc-devel maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to