Re: [fpc-pascal] Get TMethod from function reference

2022-09-19 Thread Hairy Pixels via fpc-pascal
> On Sep 19, 2022, at 4:17 PM, Sven Barth 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,

Re: [fpc-pascal] Get TMethod from function reference

2022-09-19 Thread Sven Barth via fpc-pascal
Hairy Pixels schrieb am So., 18. Sep. 2022, 02:50: > > > > On Sep 17, 2022, at 10:57 PM, Sven Barth > wrote: > > > > === code begin === > > > > type > > TProc = reference to procedure; > > TMyClass = class > > procedure DoThis; > > end; > > > > TCapturer = class(TInterfacedObject, TP

Re: [fpc-pascal] Get TMethod from function reference

2022-09-17 Thread Hairy Pixels via fpc-pascal
> On Sep 17, 2022, at 10:57 PM, Sven Barth wrote: > > === code begin === > > type > TProc = reference to procedure; > TMyClass = class > procedure DoThis; > end; > > TCapturer = class(TInterfacedObject, TProc) > m: procedure of object; > procedure Anonymous1; > > proc

Re: [fpc-pascal] Get TMethod from function reference

2022-09-17 Thread Sven Barth via fpc-pascal
Am 16.09.2022 um 03:53 schrieb Hairy Pixels: On Sep 11, 2022, at 3:28 PM, Ondrej Pokorny via fpc-pascal 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

Re: [fpc-pascal] Get TMethod from function reference

2022-09-15 Thread Hairy Pixels via fpc-pascal
> On Sep 11, 2022, at 3:28 PM, Ondrej Pokorny via fpc-pascal > 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

Re: [fpc-pascal] Get TMethod from function reference

2022-09-15 Thread Sven Barth via fpc-pascal
Am 15.09.2022 um 15:30 schrieb Hairy Pixels: On Sep 15, 2022, at 12:28 PM, Sven Barth wrote: As mentioned elsewhere function references are in fact interfaces. And you can't retrieve a method pointer to a interface function, cause relying on that would result in either memory leaks or prema

Re: [fpc-pascal] Get TMethod from function reference

2022-09-15 Thread Hairy Pixels via fpc-pascal
> On Sep 15, 2022, at 12:28 PM, Sven Barth wrote: > > As mentioned elsewhere function references are in fact interfaces. And you > can't retrieve a method pointer to a interface function, cause relying on > that would result in either memory leaks or premature release of the > interface, bec

Re: [fpc-pascal] Get TMethod from function reference

2022-09-14 Thread Sven Barth via fpc-pascal
Am 08.09.2022 um 16:55 schrieb Hairy Pixels via fpc-pascal: 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 TMyCl

Re: [fpc-pascal] Get TMethod from function reference

2022-09-11 Thread Ondrej Pokorny via fpc-pascal
Am 09.09.2022 um 00:49 schrieb Hairy Pixels via fpc-pascal: On Sep 8, 2022, at 11:14 AM, Michael Van Canneyt via fpc-pascal wrote: It must keep this information somewhere, but this does not mean you can typecast it to a TMethod. Indeed. I wonder if this information could be exposed by some m

Re: [fpc-pascal] Get TMethod from function reference

2022-09-08 Thread Hairy Pixels via fpc-pascal
> On Sep 8, 2022, at 11:14 AM, Michael Van Canneyt via fpc-pascal > wrote: > > It must keep this information somewhere, but this does not mean you can > typecast it to a TMethod. Indeed. I wonder if this information could be exposed by some method in the interface? It would be useful to int

Re: [fpc-pascal] Get TMethod from function reference

2022-09-08 Thread Michael Van Canneyt via fpc-pascal
On Thu, 8 Sep 2022, Hairy Pixels via fpc-pascal wrote: On Sep 8, 2022, at 9:09 AM, Michael Van Canneyt wrote: 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

Re: [fpc-pascal] Get TMethod from function reference

2022-09-08 Thread Hairy Pixels via fpc-pascal
> On Sep 8, 2022, at 9:09 AM, Michael Van Canneyt > wrote: > > 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)

Re: [fpc-pascal] Get TMethod from function reference

2022-09-08 Thread Michael Van Canneyt via fpc-pascal
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

[fpc-pascal] Get TMethod from function reference

2022-09-08 Thread Hairy Pixels via fpc-pascal
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