[fpc-pascal] Get TMethod from function reference

Hairy Pixels genericptr at gmail.com
Mon Sep 19 16:15:50 CEST 2022



> On Sep 19, 2022, at 4:17 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
> 
> === code begin ===
> 
> Proc1 := @c.OnChange;
> Proc2 := @c.OnClick;
> Proc3 := @c2.OnChange;
> 
> === code end ===
> 
> Will result in the following capture object:
> 
> === code begin ===
> 
> type
>   TCapturer = class(TInterfacedObject, TProc1, TProc2, TProc3)
>     m1: TNotifyEvent;
>     m2: TNotifyEvent;
>     m3: TNotifyEvent;
> 
>     procedure Anonymous1(Sender :TObject); //will call m1
>     procedure Anonymous2(Sender: TObject); // will call m2
>     procedure Anonymous3(Sender: TObject); // will call m3
>   end;
> 
> === code end ===
> 

Interesting, so all reference assignments in a scope generate a single TCapturer? Yeah that makes what I want impossible unless specific support was added to get back one of those fields.

So I guess I need to make a record wrapper for the reference stores the target class. Thankfully you fixed that crash so I can do this now. :)

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list