I knew that methods on interfaces were not compatible with the procedure of object
(like [WayBack] TProc)or function of object
construct, but they are also not compatible with the reference to procedure
or reference to function
construct.
Via: [WayBack] I try to call an Interface method from TThread.Syncrhonize()…and Berlin don’t accept that… – Paul TOTH – Google+
If you want it fixed, vote for [RSP-13007] Interface methods are not assignable to anonymous method variable – Embarcadero Technologies (Thanks Stefan Glienke).
You can work around it with an anonymous method.
This won’t work:
program Project1; {$APPTYPE CONSOLE} uses SysUtils; type ITest = interface ['{B5AD87E8-A3DF-4B83-BE14-997C2E76A06C}'] procedure Run; end; TTest = class(TInterfacedObject, ITest) procedure Run; end; procedure TTest.Run; begin Writeln('PASS') end; var test: ITest; // <- change this to TTest and it compiles proc: TProc; begin test := TTest.Create; proc := procedure begin test.Run; end; // <- this compiles proc := test.Run; // E2010 Incompatible types: 'TProc' and 'procedure, untyped pointer or untyped parameter' proc(); Readln; end.
–jeroen