Re: @ operator ? Or maybe not



On Mon, 24 Oct 2005 23:15:47 +0200, "Tom de Neef" <tdeneef@xxxxxxxx>
wrote:

>Suppose

>type
> myClass = class
> button : Tbutton;
> procedure method1(Sender: TObject);
> procedure method2(Sender: TObject);
> end;

>And somewhere I've assigned
>myClass.button.OnClick:=myClass.method1;

>How can I now verify if the OnClick is assigned to method1 or method2 ?
>I'd like to do
> button.enabled:=(@button.Onclick = @method1);

>But that isn't valid...

Rather than using @ use Addr it is a bit more typing but much more
explicit

- Addr( Button.OnClick ) is a storage location - Its address is
meaningless what is stored there is interesting

- Addr( Method1 ) is the address of the start of a procedure

- probably an Integer tucked away in the memory located by
Addr(Button.Onclick)

I have a nasty gut feeling that what you are trying to do is seriously
bad design - you are trying to let the Children identify their
Parents, which is a recipe for spaghetti

Right now I can't see a clean solution, but my gut feeling is that the
Button should be a descendant of TButton that has a property that can
be interrogated by the OnClick event handler

If ( Sender Is TtdnButton ) Then
( Sender As TtdnButton ).DoThisOrThatThing

I'm not sure, but I do know that what you are trying to do (or rather
the way you are trying to do it) is very, very wrong
- like it will bite you in the ***

.


Quantcast