Delegates, Events and static callbacks 
Author Message
 Delegates, Events and static callbacks

I have a form in which I want to declare a handler method (callback)
which I can then use to set-up a delegate, and hence receive events
from another class. In particular, this is to receive validation
errors from the XmlValidatingReader class.

The idea is then to write the Message property of the eventargs
argument to a text box member variable of the form... only I can't. As
the handler method has to be static, I can't reference member
variables. As a quick hack I've declared the text box to also be
static, but this obviously breaks down if I want to have more than one
instance of my form. What's the approch i should be taking here? is
there something I'm missing? Now, I'm no great Java fan, but the use
of interfaces does make instance-based event handling a little more
intuitive.



Mon, 01 Mar 2004 23:18:37 GMT  
 Delegates, Events and static callbacks

I have a form in which I want to declare a handler method
(callback) which I can then use to set-up a delegate, and
hence receive events from another class. In particular,
this is to receive validation errors from the
XmlValidatingReader class.

The idea is then to write the Message property of the
eventargs argument to a text box member variable of the
form... only I can't. As the handler method has to be
static, I can't reference member variables. As a quick
hack I've declared the text box to also be static, but
this obviously breaks down if I want to have more than one
instance of my form. What's the approch i should be taking
here? is there something I'm missing? Now, I'm no great
Java fan, but the use of interfaces does make instance-
based event handling a little more intuitive.



Mon, 01 Mar 2004 23:14:29 GMT  
 Delegates, Events and static callbacks
Handler methods don't need to be static; you can declare a delegate to an
instance method.


Quote:

> I have a form in which I want to declare a handler method
> (callback) which I can then use to set-up a delegate, and
> hence receive events from another class. In particular,
> this is to receive validation errors from the
> XmlValidatingReader class.

> The idea is then to write the Message property of the
> eventargs argument to a text box member variable of the
> form... only I can't. As the handler method has to be
> static, I can't reference member variables. As a quick
> hack I've declared the text box to also be static, but
> this obviously breaks down if I want to have more than one
> instance of my form. What's the approch i should be taking
> here? is there something I'm missing? Now, I'm no great
> Java fan, but the use of interfaces does make instance-
> based event handling a little more intuitive.



Tue, 02 Mar 2004 00:23:58 GMT  
 Delegates, Events and static callbacks

That's great news; I'll modify my code.

Perhaps you could explain the bit in your book at the top of page 183... 'Two static functions are declared that match this delegate (all delegates must be static functions)...'

Is this referring to something else that must be static?

thanks

Vinnie

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 02 Mar 2004 02:51:37 GMT  
 Delegates, Events and static callbacks
A delegate can be static or NOT. Instance methods as well
as static methods are supported.

So in your form, you can add a private event handler and
instantiate your delegate (event handler) with that
private method.

There are some very good books about delegates and events
and also some good papers on msdn.

Quote:
>-----Original Message-----

>I have a form in which I want to declare a handler method
>(callback) which I can then use to set-up a delegate, and
>hence receive events from another class. In particular,
>this is to receive validation errors from the
>XmlValidatingReader class.

>The idea is then to write the Message property of the
>eventargs argument to a text box member variable of the
>form... only I can't. As the handler method has to be
>static, I can't reference member variables. As a quick
>hack I've declared the text box to also be static, but
>this obviously breaks down if I want to have more than one
>instance of my form. What's the approch i should be
taking
>here? is there something I'm missing? Now, I'm no great
>Java fan, but the use of interfaces does make instance-
>based event handling a little more intuitive.

>.



Tue, 02 Mar 2004 06:03:52 GMT  
 Delegates, Events and static callbacks

Quote:

> That's great news; I'll modify my code.

> Perhaps you could explain the bit in your book at the top of page 183...

'Two static functions are declared that match this delegate (all delegates
must be static functions)...'

Quote:

> Is this referring to something else that must be static?

No, that's a mistake that's in early printings of the book. Sorry for any
confusion that it caused.


Wed, 03 Mar 2004 02:30:46 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Interface callback implementation (vs Delegates & Events)

2. callbacks / delegates

3. Cross Class Delegate/Callback Problem

4. Callbacks / Delegates into DLLs

5. Problems with delegates & async callbacks

6. callback using delegates

7. interop delegate/callback problem

8. asynchronous delegate callback...

9. using non-static member functions using delegates

10. Do delegates have to be static?

11. Delegates/Events...

12. Events and Delegates

 

 
Powered by phpBB® Forum Software