[fpc-pascal] Get TMethod from function reference
    Michael Van Canneyt 
    michael at freepascal.org
       
    Thu Sep  8 17:09:35 CEST 2022
    
    
  
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.
    
    
More information about the fpc-pascal
mailing list