I created a class method in a class that implements an interface, but I cannot define it inside an interface.
IMyClass = interface procedure someproc(); class function myfunc() : TMyClass;
I want myfunc() create and return an instance of TMyClass . For example:
somefunc( TMyClass.myfunc(), ... );
creates an instance of TMyClass and passes it to somefunc .
I can define function myfunc() : TMyClass; in the IMyClass interface, but if I put a class in front of it, the compiler will give me an error. If I leave this, it will give me several other errors "E2291 There is no implementation of the xyz.myfunc interface method" It simply does not accept the same signature in the interface as in the class.
I thought I saw this work before (class methods defined in interfaces), but maybe not.
If this is not directly supported, how do you do it?
(I use Delphi XE5 if that matters.)
oop interface delphi
David schwartz
source share