[fpc-pascal] Get TMethod from function reference

Hairy Pixels genericptr at gmail.com
Fri Sep 16 03:53:35 CEST 2022

> On Sep 11, 2022, at 3:28 PM, Ondrej Pokorny via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> You should be able to get the Invoke procedure pointer from the RTTI.

Sorry Sven mentioned this I must have glossed over it. So yes I am storing the function reference in a class so it’s not going to get freed.

Given this example here can you explain how to get the procedure pointer from the RTTI? Even so if you get the procedure pointer you need the class instance also, which reference must be keeping somewhere right?

  TProc = reference to procedure;
  TMyClass = class
    procedure DoThis;

  p: TProc;
  c: TMyClass;
  c := TMyClass.Create;
  p := c.DoThis;
  // Can I get the refefence to "c" back using the RTTI?

	Ryan Joseph

More information about the fpc-pascal mailing list