On Thu, 8 Sep 2022, Hairy Pixels via fpc-pascal wrote:

A function reference can call a class method but can you get the TMethod data 
from function references? It was possible with “is object” to cast to TMethod 
but that doesn’t seem to be possible with references.

=========

type
 TMyClass = class
   constructor Create;
   procedure DoThis;
 end;

 constructor TMyClass.Create;
 var
   proc: reference to procedure;
 begin
   proc := @DoThis;
   writeln(Assigned(PMethod(proc)^.data)); // FALSE
 end;

To me it seems logical that you cannot do this, since a function reference is 
actually an
interface, and there is no actual object to back it up.

Your function reference could also be a regular procedure (no data at all) or 
even a local
procedure.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to