Say I have a Button1.OnClick event linked to Button1Click procedure. I also have Button2.OnClick linked to some other procedure. How do I check that both events are linked to different or same procedure from runtime?
I tried to test if:
- Button1.OnClick = Button2.OnClick, but that gave me an error (Not enough actual parameters)
- @(Button1.OnClick) = @(Button2.OnClick), error again (Not enough actual parameters)
How do I test it properly?
A method reference can be broken down in to two parts, the pointer to the object and the pointer to the method itself. There is a convenient record type defined in the
Systemunit calledTMethodthat allows us to do that break down.With that knowledge, we can write something like this:
Hope this helps. 🙂
Edit: Just to lay out in a better format the problem I am trying to solve here (as alluded to in the comments).
If you have two forms, both instantiated from the same base class:
and you assign the same method from those forms to the two buttons:
And compare the two
OnClickproperties, you will find that theCodeis the same, but theDatais different. That is because it’s the same method, but on two different instantiations of the class…Now, if you had two methods on the same object:
Then their
Datawill be the same, but theirCodewill be different.