I'm wondering if this the following is possible or not, if yes, how? Code example please.
What I want to do is store a 'method pointer' in the integer Tag value of a TComponent-derived object, and sometime later call the stored method. You can assume all met methods have the same definition.
Thanks!
No, it's not possible. A method of object is equivalent to TMethod:
TMethod = record
Code, Data: Pointer;
end;
The Code
field is the address of the method, and the Data
field is the hidden Self
parameter that's passed into every object method. The record is the same size as an Int64, so if you cast it as a plain Integer you'll lose half of it.
You could allocate a TMethod record on the heap using GetMem and then store the address of that in the Tag property, as long as you remembered to free it when you're done with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With