473,735 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Matching Event Handlers in an Interface

Mr "yEaH rIgHt" posted the following link about a week ago in answer to my
question about removing event handlers.
http://www.vbinfozine.com/t_bindevt.shtml


Following on from that post, the following issues still exist.

The article shows how to find methods on a receiver that match the pattern
OnXXXX given the sender. It loops through the sender events and tries to get
methods from the receiver that match the pattern. For each one it finds it
either adds or removes a handler for the event.

This is great where there is a straight forward mapping, but I don't have a
straight forward mapping. For example, although I could easily use this
pattern in many cases, there are situations where the sender has two similar
events, only one of which a particular receiver is going to service.

Let's say that my sender has an event ValueChanged. My receiver could easily
have a method OnValueChanged that could be linked up using the technique
above. As it happens, my receiver has a method MyControl_Value Changed, but
this also works with the technique above.

The problem arises where my sender has two values that can change. In this
case it can raise two events: Value1Changed and Value2Changed. My receiver
only services one of these, and which one is determined at runtime.
Therefore, the receiver still has a method MyControl_Value Changed, because
it knows nothing of a sender that has two values.

This breaks the pattern, as there is now easy way to transform the event
Value2Changed into the method name MyControl_Value Changed.

So, ...

I am trying to find a way of looping through the sender's events, as before,
but for each one I want to get the invocation list, and see if my receiver
is in it. Only if it is do I want to remove the handler. I have got this far

<code>
Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal receiver
As Object)

Dim SenderType As Type
Dim ReceiverType As Type

Dim dlgts() As [Delegate]

SenderType = sender.GetType( )
ReceiverType = receiver.GetTyp e()

For Each ei As EventInfo In SenderType.GetE vents()

' For each event that the sender can raise, get the invocation
list
dlgts = sender.Events.I tem( *WHAT GOES
HERE?* ).GetInvocation List()

For Each dlgt As [Delegate] In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
ei.RemoveEventH andler(sender, dlgt)
End If
Next dlgt

Next ei

End Sub
</code>

Can someone suggest what might replace the capitalised text? Alternatively,
can
anyone think of another way of achieving the same end?

Thanks.

Charles
Nov 20 '05 #1
13 3513
Could someone have a look at this please. It seems to me that it should be
possible to get a list of handlers for an event and then remove any handler
that is in a given object. I just can't figure out how to do it.

Anyone?

Charles
"Charles Law" <bl***@nowhere. com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my
question about removing event handlers.
http://www.vbinfozine.com/t_bindevt.shtml
Following on from that post, the following issues still exist.

The article shows how to find methods on a receiver that match the pattern
OnXXXX given the sender. It loops through the sender events and tries to

get methods from the receiver that match the pattern. For each one it finds it
either adds or removes a handler for the event.

This is great where there is a straight forward mapping, but I don't have a straight forward mapping. For example, although I could easily use this
pattern in many cases, there are situations where the sender has two similar events, only one of which a particular receiver is going to service.

Let's say that my sender has an event ValueChanged. My receiver could easily have a method OnValueChanged that could be linked up using the technique
above. As it happens, my receiver has a method MyControl_Value Changed, but
this also works with the technique above.

The problem arises where my sender has two values that can change. In this
case it can raise two events: Value1Changed and Value2Changed. My receiver
only services one of these, and which one is determined at runtime.
Therefore, the receiver still has a method MyControl_Value Changed, because
it knows nothing of a sender that has two values.

This breaks the pattern, as there is now easy way to transform the event
Value2Changed into the method name MyControl_Value Changed.

So, ...

I am trying to find a way of looping through the sender's events, as before, but for each one I want to get the invocation list, and see if my receiver
is in it. Only if it is do I want to remove the handler. I have got this far
<code>
Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal receiver As Object)

Dim SenderType As Type
Dim ReceiverType As Type

Dim dlgts() As [Delegate]

SenderType = sender.GetType( )
ReceiverType = receiver.GetTyp e()

For Each ei As EventInfo In SenderType.GetE vents()

' For each event that the sender can raise, get the invocation
list
dlgts = sender.Events.I tem( *WHAT GOES
HERE?* ).GetInvocation List()

For Each dlgt As [Delegate] In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
ei.RemoveEventH andler(sender, dlgt)
End If
Next dlgt

Next ei

End Sub
</code>

Can someone suggest what might replace the capitalised text? Alternatively, can
anyone think of another way of achieving the same end?

Thanks.

Charles

Nov 20 '05 #2
Charles,
For Each dlgt As [Delegate] In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
Remember that [Delegate] is short hand for System.Delegate . That
System.Delegate is a class with methods & properties.

I would start by looking at the methods & properties available on the
System.Delegate class.

http://msdn.microsoft.com/library/de...ClassTopic.asp

Specifically the System.Delegate .Target and System.Delegate Method
properties. The System.Delegate .Equals method may or may not help.

Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl... Mr "yEaH rIgHt" posted the following link about a week ago in answer to my
question about removing event handlers.
http://www.vbinfozine.com/t_bindevt.shtml
Following on from that post, the following issues still exist.

The article shows how to find methods on a receiver that match the pattern
OnXXXX given the sender. It loops through the sender events and tries to

get methods from the receiver that match the pattern. For each one it finds it
either adds or removes a handler for the event.

This is great where there is a straight forward mapping, but I don't have a straight forward mapping. For example, although I could easily use this
pattern in many cases, there are situations where the sender has two similar events, only one of which a particular receiver is going to service.

Let's say that my sender has an event ValueChanged. My receiver could easily have a method OnValueChanged that could be linked up using the technique
above. As it happens, my receiver has a method MyControl_Value Changed, but
this also works with the technique above.

The problem arises where my sender has two values that can change. In this
case it can raise two events: Value1Changed and Value2Changed. My receiver
only services one of these, and which one is determined at runtime.
Therefore, the receiver still has a method MyControl_Value Changed, because
it knows nothing of a sender that has two values.

This breaks the pattern, as there is now easy way to transform the event
Value2Changed into the method name MyControl_Value Changed.

So, ...

I am trying to find a way of looping through the sender's events, as before, but for each one I want to get the invocation list, and see if my receiver
is in it. Only if it is do I want to remove the handler. I have got this far
<code>
Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal receiver As Object)

Dim SenderType As Type
Dim ReceiverType As Type

Dim dlgts() As [Delegate]

SenderType = sender.GetType( )
ReceiverType = receiver.GetTyp e()

For Each ei As EventInfo In SenderType.GetE vents()

' For each event that the sender can raise, get the invocation
list
dlgts = sender.Events.I tem( *WHAT GOES
HERE?* ).GetInvocation List()

For Each dlgt As [Delegate] In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
ei.RemoveEventH andler(sender, dlgt)
End If
Next dlgt

Next ei

End Sub
</code>

Can someone suggest what might replace the capitalised text? Alternatively, can
anyone think of another way of achieving the same end?

Thanks.

Charles

Nov 20 '05 #3
Hi Jay

Yes, I think that one of those will allow me to test for equality with the
receiver. My first hurdle, though is this line:
dlgts = sender.Events.I tem( *WHAT GOES HERE?* ).GetInvocation List()
Given the sender object, I cannot for the life of me see how to drill down
to the invocation list. The Item member seems to need a key in the shape of
an object, but what key should I use? I have searched and searched but
cannot find an example of this anywhere. Can you think what might work?

Thanks.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:Om******** ******@tk2msftn gp13.phx.gbl... Charles,
For Each dlgt As [Delegate] In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
Remember that [Delegate] is short hand for System.Delegate . That
System.Delegate is a class with methods & properties.

I would start by looking at the methods & properties available on the
System.Delegate class.

http://msdn.microsoft.com/library/de...ClassTopic.asp
Specifically the System.Delegate .Target and System.Delegate Method
properties. The System.Delegate .Equals method may or may not help.

Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers.
http://www.vbinfozine.com/t_bindevt.shtml
Following on from that post, the following issues still exist.

The article shows how to find methods on a receiver that match the pattern OnXXXX given the sender. It loops through the sender events and tries to

get
methods from the receiver that match the pattern. For each one it finds it either adds or removes a handler for the event.

This is great where there is a straight forward mapping, but I don't have a
straight forward mapping. For example, although I could easily use this
pattern in many cases, there are situations where the sender has two

similar
events, only one of which a particular receiver is going to service.

Let's say that my sender has an event ValueChanged. My receiver could

easily
have a method OnValueChanged that could be linked up using the technique
above. As it happens, my receiver has a method MyControl_Value Changed,

but this also works with the technique above.

The problem arises where my sender has two values that can change. In this case it can raise two events: Value1Changed and Value2Changed. My receiver only services one of these, and which one is determined at runtime.
Therefore, the receiver still has a method MyControl_Value Changed, because it knows nothing of a sender that has two values.

This breaks the pattern, as there is now easy way to transform the event
Value2Changed into the method name MyControl_Value Changed.

So, ...

I am trying to find a way of looping through the sender's events, as

before,
but for each one I want to get the invocation list, and see if my receiver is in it. Only if it is do I want to remove the handler. I have got this

far

<code>
Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal

receiver
As Object)

Dim SenderType As Type
Dim ReceiverType As Type

Dim dlgts() As [Delegate]

SenderType = sender.GetType( )
ReceiverType = receiver.GetTyp e()

For Each ei As EventInfo In SenderType.GetE vents()

' For each event that the sender can raise, get the invocation list
dlgts = sender.Events.I tem( *WHAT GOES
HERE?* ).GetInvocation List()

For Each dlgt As [Delegate] In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
ei.RemoveEventH andler(sender, dlgt)
End If
Next dlgt

Next ei

End Sub
</code>

Can someone suggest what might replace the capitalised text?

Alternatively,
can
anyone think of another way of achieving the same end?

Thanks.

Charles


Nov 20 '05 #4
Charles,
A specific hidden field that the designer of the class supplied when they
added the Event to the HandlerList.

I suspect in your project that sender.Events is nothing, or an empty list.

Generally the class itself will create a key object (via New Object
literally) that is used to index into the Events collection. If you are
using the Events collection you should know what that key is. In that you
would have supplied the key to add the event to the collection.

Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Jay

Yes, I think that one of those will allow me to test for equality with the
receiver. My first hurdle, though is this line:
dlgts = sender.Events.I tem( *WHAT GOES HERE?* ).GetInvocation List()
Given the sender object, I cannot for the life of me see how to drill down
to the invocation list. The Item member seems to need a key in the shape

of an object, but what key should I use? I have searched and searched but
cannot find an example of this anywhere. Can you think what might work?

Thanks.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:Om******** ******@tk2msftn gp13.phx.gbl...
Charles,
For Each dlgt As [Delegate] In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
Remember that [Delegate] is short hand for System.Delegate . That
System.Delegate is a class with methods & properties.

I would start by looking at the methods & properties available on the
System.Delegate class.

http://msdn.microsoft.com/library/de...ClassTopic.asp

Specifically the System.Delegate .Target and System.Delegate Method
properties. The System.Delegate .Equals method may or may not help.

Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my
question about removing event handlers.

> http://www.vbinfozine.com/t_bindevt.shtml

Following on from that post, the following issues still exist.

The article shows how to find methods on a receiver that match the pattern OnXXXX given the sender. It loops through the sender events and tries
to
get
methods from the receiver that match the pattern. For each one it
finds
it either adds or removes a handler for the event.

This is great where there is a straight forward mapping, but I don't have
a
straight forward mapping. For example, although I could easily use

this pattern in many cases, there are situations where the sender has two

similar
events, only one of which a particular receiver is going to service.

Let's say that my sender has an event ValueChanged. My receiver could

easily
have a method OnValueChanged that could be linked up using the technique above. As it happens, my receiver has a method MyControl_Value Changed,

but this also works with the technique above.

The problem arises where my sender has two values that can change. In this case it can raise two events: Value1Changed and Value2Changed. My receiver only services one of these, and which one is determined at runtime.
Therefore, the receiver still has a method MyControl_Value Changed, because it knows nothing of a sender that has two values.

This breaks the pattern, as there is now easy way to transform the event Value2Changed into the method name MyControl_Value Changed.

So, ...

I am trying to find a way of looping through the sender's events, as

before,
but for each one I want to get the invocation list, and see if my receiver is in it. Only if it is do I want to remove the handler. I have got
this far

<code>
Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal

receiver
As Object)

Dim SenderType As Type
Dim ReceiverType As Type

Dim dlgts() As [Delegate]

SenderType = sender.GetType( )
ReceiverType = receiver.GetTyp e()

For Each ei As EventInfo In SenderType.GetE vents()

' For each event that the sender can raise, get the

invocation list
dlgts = sender.Events.I tem( *WHAT GOES
HERE?* ).GetInvocation List()

For Each dlgt As [Delegate] In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
ei.RemoveEventH andler(sender, dlgt)
End If
Next dlgt

Next ei

End Sub
</code>

Can someone suggest what might replace the capitalised text?

Alternatively,
can
anyone think of another way of achieving the same end?

Thanks.

Charles



Nov 20 '05 #5
Jay

I did see once where New Object was used for adding keys, but, as you
suggest that was in a user rolled method.

It seems, from what you are saying, that the invocation list is for user use
only. I had expected that the 'framework' would have a method - that I could
get access to - that allowed me to see all the handlers/delegates to be
called for an event. After all, if this is not the case, how does the
framework do it?

When an event is raised, there must be a list somewhere, of delegates that
will be invoked/called. If I could just get access to/enumerate those
handlers, I would be home and dry.

Incidentally, sender.Events is *not* nothing in my project, and I have only
called AddHandler to add a handler for an event.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Charles,
A specific hidden field that the designer of the class supplied when they
added the Event to the HandlerList.

I suspect in your project that sender.Events is nothing, or an empty list.

Generally the class itself will create a key object (via New Object
literally) that is used to index into the Events collection. If you are
using the Events collection you should know what that key is. In that you
would have supplied the key to add the event to the collection.

Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Jay

Yes, I think that one of those will allow me to test for equality with the
receiver. My first hurdle, though is this line:
dlgts = sender.Events.I tem( *WHAT GOES HERE?* ).GetInvocation List()
Given the sender object, I cannot for the life of me see how to drill down to the invocation list. The Item member seems to need a key in the shape

of
an object, but what key should I use? I have searched and searched but
cannot find an example of this anywhere. Can you think what might work?

Thanks.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:Om******** ******@tk2msftn gp13.phx.gbl...
Charles,
> For Each dlgt As [Delegate] In dlgts
> If *TEST FOR DELEGATE BEING ON RECEIVER?* Then

Remember that [Delegate] is short hand for System.Delegate . That
System.Delegate is a class with methods & properties.

I would start by looking at the methods & properties available on the
System.Delegate class.

http://msdn.microsoft.com/library/de...ClassTopic.asp

Specifically the System.Delegate .Target and System.Delegate Method
properties. The System.Delegate .Equals method may or may not help.

Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:eh******** ******@TK2MSFTN GP09.phx.gbl...
> Mr "yEaH rIgHt" posted the following link about a week ago in answer to
my
> question about removing event handlers.
>
> > http://www.vbinfozine.com/t_bindevt.shtml
>
> Following on from that post, the following issues still exist.
>
> The article shows how to find methods on a receiver that match the

pattern
> OnXXXX given the sender. It loops through the sender events and tries to get
> methods from the receiver that match the pattern. For each one it finds
it
> either adds or removes a handler for the event.
>
> This is great where there is a straight forward mapping, but I don't

have
a
> straight forward mapping. For example, although I could easily use this > pattern in many cases, there are situations where the sender has two
similar
> events, only one of which a particular receiver is going to service.
>
> Let's say that my sender has an event ValueChanged. My receiver
could easily
> have a method OnValueChanged that could be linked up using the

technique > above. As it happens, my receiver has a method
MyControl_Value Changed, but
> this also works with the technique above.
>
> The problem arises where my sender has two values that can change.
In this
> case it can raise two events: Value1Changed and Value2Changed. My

receiver
> only services one of these, and which one is determined at runtime.
> Therefore, the receiver still has a method MyControl_Value Changed,

because
> it knows nothing of a sender that has two values.
>
> This breaks the pattern, as there is now easy way to transform the

event > Value2Changed into the method name MyControl_Value Changed.
>
> So, ...
>
> I am trying to find a way of looping through the sender's events, as
before,
> but for each one I want to get the invocation list, and see if my

receiver
> is in it. Only if it is do I want to remove the handler. I have got this far
>
> <code>
> Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal
receiver
> As Object)
>
> Dim SenderType As Type
> Dim ReceiverType As Type
>
> Dim dlgts() As [Delegate]
>
> SenderType = sender.GetType( )
> ReceiverType = receiver.GetTyp e()
>
> For Each ei As EventInfo In SenderType.GetE vents()
>
> ' For each event that the sender can raise, get the

invocation
> list
> dlgts = sender.Events.I tem( *WHAT GOES
> HERE?* ).GetInvocation List()
>
> For Each dlgt As [Delegate] In dlgts
> If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
> ei.RemoveEventH andler(sender, dlgt)
> End If
> Next dlgt
>
> Next ei
>
> End Sub
> </code>
>
> Can someone suggest what might replace the capitalised text?
Alternatively,
> can
> anyone think of another way of achieving the same end?
>
> Thanks.
>
> Charles
>
>



Nov 20 '05 #6
Charles
sender.Events is totally different then Delegate.GetInv ocationList.

Delegate.GetInv ocationList is how you see all the handlers to be called for
an event.

sender.Events is all the invocationlists for all the events on a component,
if you designed your component to be used that way. (read its a C# thing).
Incidentally, sender.Events is *not* nothing in my project, and I have only called AddHandler to add a handler for an event. As I stated, I would expect it to be Nothing or an empty list, is it an
empty list?

Hope this helps
Jay

"Charles Law" <bl***@nowhere. com> wrote in message
news:Oz******** ******@TK2MSFTN GP09.phx.gbl... Jay

I did see once where New Object was used for adding keys, but, as you
suggest that was in a user rolled method.

It seems, from what you are saying, that the invocation list is for user use only. I had expected that the 'framework' would have a method - that I could get access to - that allowed me to see all the handlers/delegates to be
called for an event. After all, if this is not the case, how does the
framework do it?

When an event is raised, there must be a list somewhere, of delegates that
will be invoked/called. If I could just get access to/enumerate those
handlers, I would be home and dry.

Incidentally, sender.Events is *not* nothing in my project, and I have only called AddHandler to add a handler for an event.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Charles,
A specific hidden field that the designer of the class supplied when they
added the Event to the HandlerList.

I suspect in your project that sender.Events is nothing, or an empty list.
Generally the class itself will create a key object (via New Object
literally) that is used to index into the Events collection. If you are
using the Events collection you should know what that key is. In that you would have supplied the key to add the event to the collection.

Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi Jay

Yes, I think that one of those will allow me to test for equality with the receiver. My first hurdle, though is this line:

> dlgts = sender.Events.I tem( *WHAT GOES HERE?* ).GetInvocation List()

Given the sender object, I cannot for the life of me see how to drill down to the invocation list. The Item member seems to need a key in the shape of
an object, but what key should I use? I have searched and searched but
cannot find an example of this anywhere. Can you think what might
work?
Thanks.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:Om******** ******@tk2msftn gp13.phx.gbl...
> Charles,
> > For Each dlgt As [Delegate] In dlgts
> > If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
>
> Remember that [Delegate] is short hand for System.Delegate . That
> System.Delegate is a class with methods & properties.
>
> I would start by looking at the methods & properties available on the > System.Delegate class.
>
>

http://msdn.microsoft.com/library/de...ClassTopic.asp
>
> Specifically the System.Delegate .Target and System.Delegate Method
> properties. The System.Delegate .Equals method may or may not help.
>
> Hope this helps
> Jay
>
>
> "Charles Law" <bl***@nowhere. com> wrote in message
> news:eh******** ******@TK2MSFTN GP09.phx.gbl...
> > Mr "yEaH rIgHt" posted the following link about a week ago in answer to
my
> > question about removing event handlers.
> >
> > > http://www.vbinfozine.com/t_bindevt.shtml
> >
> > Following on from that post, the following issues still exist.
> >
> > The article shows how to find methods on a receiver that match the
pattern
> > OnXXXX given the sender. It loops through the sender events and tries
to
> get
> > methods from the receiver that match the pattern. For each one it

finds
it
> > either adds or removes a handler for the event.
> >
> > This is great where there is a straight forward mapping, but I
don't have
> a
> > straight forward mapping. For example, although I could easily use

this
> > pattern in many cases, there are situations where the sender has two > similar
> > events, only one of which a particular receiver is going to service. > >
> > Let's say that my sender has an event ValueChanged. My receiver

could > easily
> > have a method OnValueChanged that could be linked up using the

technique
> > above. As it happens, my receiver has a method MyControl_Value Changed, but
> > this also works with the technique above.
> >
> > The problem arises where my sender has two values that can change. In this
> > case it can raise two events: Value1Changed and Value2Changed. My
receiver
> > only services one of these, and which one is determined at runtime. > > Therefore, the receiver still has a method MyControl_Value Changed,
because
> > it knows nothing of a sender that has two values.
> >
> > This breaks the pattern, as there is now easy way to transform the

event
> > Value2Changed into the method name MyControl_Value Changed.
> >
> > So, ...
> >
> > I am trying to find a way of looping through the sender's events, as > before,
> > but for each one I want to get the invocation list, and see if my
receiver
> > is in it. Only if it is do I want to remove the handler. I have

got this
> far
> >
> > <code>
> > Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal
> receiver
> > As Object)
> >
> > Dim SenderType As Type
> > Dim ReceiverType As Type
> >
> > Dim dlgts() As [Delegate]
> >
> > SenderType = sender.GetType( )
> > ReceiverType = receiver.GetTyp e()
> >
> > For Each ei As EventInfo In SenderType.GetE vents()
> >
> > ' For each event that the sender can raise, get the
invocation
> > list
> > dlgts = sender.Events.I tem( *WHAT GOES
> > HERE?* ).GetInvocation List()
> >
> > For Each dlgt As [Delegate] In dlgts
> > If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
> > ei.RemoveEventH andler(sender, dlgt)
> > End If
> > Next dlgt
> >
> > Next ei
> >
> > End Sub
> > </code>
> >
> > Can someone suggest what might replace the capitalised text?
> Alternatively,
> > can
> > anyone think of another way of achieving the same end?
> >
> > Thanks.
> >
> > Charles
> >
> >
>
>



Nov 20 '05 #7
Jay
sender.Events is totally different then Delegate.GetInv ocationList.
I didn't mean to suggest that I thought these were the same. Rather than get
bogged down in (perhaps) my misunderstandin g, I will state my aim in PDL

For each event that can be raised by an object (sender)
For each event handler currently attached for the given event
If given event handler is on known target (receiver)
Remove handler
End if
Next event handler
Next event

I don't know how to state it any better than that.
As I stated, I would expect it to be Nothing or an empty list, is it an
empty list?
I can't tell if it is an empty list because there is no member for
retrieving the length, and none for indexing either.

Thanks for your continued help.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:u1******** *******@tk2msft ngp13.phx.gbl.. . Charles
sender.Events is totally different then Delegate.GetInv ocationList.

Delegate.GetInv ocationList is how you see all the handlers to be called for an event.

sender.Events is all the invocationlists for all the events on a component, if you designed your component to be used that way. (read its a C# thing).
Incidentally, sender.Events is *not* nothing in my project, and I have only
called AddHandler to add a handler for an event.

As I stated, I would expect it to be Nothing or an empty list, is it an
empty list?

Hope this helps
Jay

"Charles Law" <bl***@nowhere. com> wrote in message
news:Oz******** ******@TK2MSFTN GP09.phx.gbl...
Jay

I did see once where New Object was used for adding keys, but, as you
suggest that was in a user rolled method.

It seems, from what you are saying, that the invocation list is for user

use
only. I had expected that the 'framework' would have a method - that I

could
get access to - that allowed me to see all the handlers/delegates to be
called for an event. After all, if this is not the case, how does the
framework do it?

When an event is raised, there must be a list somewhere, of delegates that
will be invoked/called. If I could just get access to/enumerate those
handlers, I would be home and dry.

Incidentally, sender.Events is *not* nothing in my project, and I have

only
called AddHandler to add a handler for an event.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Charles,
A specific hidden field that the designer of the class supplied when they added the Event to the HandlerList.

I suspect in your project that sender.Events is nothing, or an empty list.
Generally the class itself will create a key object (via New Object
literally) that is used to index into the Events collection. If you are using the Events collection you should know what that key is. In that you would have supplied the key to add the event to the collection.

Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> Hi Jay
>
> Yes, I think that one of those will allow me to test for equality with the
> receiver. My first hurdle, though is this line:
>
> > dlgts = sender.Events.I tem( *WHAT GOES
HERE?* ).GetInvocation List() >
> Given the sender object, I cannot for the life of me see how to drill
down
> to the invocation list. The Item member seems to need a key in the shape of
> an object, but what key should I use? I have searched and searched
but > cannot find an example of this anywhere. Can you think what might

work? >
> Thanks.
>
> Charles
>
>
> "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in

message
> news:Om******** ******@tk2msftn gp13.phx.gbl...
> > Charles,
> > > For Each dlgt As [Delegate] In dlgts
> > > If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
> >
> > Remember that [Delegate] is short hand for System.Delegate . That
> > System.Delegate is a class with methods & properties.
> >
> > I would start by looking at the methods & properties available on the > > System.Delegate class.
> >
> >
>

http://msdn.microsoft.com/library/de...ClassTopic.asp
> >
> > Specifically the System.Delegate .Target and System.Delegate Method
> > properties. The System.Delegate .Equals method may or may not help.
> >
> > Hope this helps
> > Jay
> >
> >
> > "Charles Law" <bl***@nowhere. com> wrote in message
> > news:eh******** ******@TK2MSFTN GP09.phx.gbl...
> > > Mr "yEaH rIgHt" posted the following link about a week ago in answer to
> my
> > > question about removing event handlers.
> > >
> > > > http://www.vbinfozine.com/t_bindevt.shtml
> > >
> > > Following on from that post, the following issues still exist.
> > >
> > > The article shows how to find methods on a receiver that match the > pattern
> > > OnXXXX given the sender. It loops through the sender events and

tries
to
> > get
> > > methods from the receiver that match the pattern. For each one it finds
> it
> > > either adds or removes a handler for the event.
> > >
> > > This is great where there is a straight forward mapping, but I don't > have
> > a
> > > straight forward mapping. For example, although I could easily use this
> > > pattern in many cases, there are situations where the sender has two > > similar
> > > events, only one of which a particular receiver is going to service. > > >
> > > Let's say that my sender has an event ValueChanged. My receiver

could
> > easily
> > > have a method OnValueChanged that could be linked up using the
technique
> > > above. As it happens, my receiver has a method

MyControl_Value Changed,
> but
> > > this also works with the technique above.
> > >
> > > The problem arises where my sender has two values that can change. In
> this
> > > case it can raise two events: Value1Changed and Value2Changed.
My > receiver
> > > only services one of these, and which one is determined at

runtime. > > > Therefore, the receiver still has a method MyControl_Value Changed, > because
> > > it knows nothing of a sender that has two values.
> > >
> > > This breaks the pattern, as there is now easy way to transform the event
> > > Value2Changed into the method name MyControl_Value Changed.
> > >
> > > So, ...
> > >
> > > I am trying to find a way of looping through the sender's events, as
> > before,
> > > but for each one I want to get the invocation list, and see if
my > receiver
> > > is in it. Only if it is do I want to remove the handler. I have

got this
> > far
> > >
> > > <code>
> > > Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal > > receiver
> > > As Object)
> > >
> > > Dim SenderType As Type
> > > Dim ReceiverType As Type
> > >
> > > Dim dlgts() As [Delegate]
> > >
> > > SenderType = sender.GetType( )
> > > ReceiverType = receiver.GetTyp e()
> > >
> > > For Each ei As EventInfo In SenderType.GetE vents()
> > >
> > > ' For each event that the sender can raise, get the
> invocation
> > > list
> > > dlgts = sender.Events.I tem( *WHAT GOES
> > > HERE?* ).GetInvocation List()
> > >
> > > For Each dlgt As [Delegate] In dlgts
> > > If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
> > > ei.RemoveEventH andler(sender, dlgt)
> > > End If
> > > Next dlgt
> > >
> > > Next ei
> > >
> > > End Sub
> > > </code>
> > >
> > > Can someone suggest what might replace the capitalised text?
> > Alternatively,
> > > can
> > > anyone think of another way of achieving the same end?
> > >
> > > Thanks.
> > >
> > > Charles
> > >
> > >
> >
> >
>
>



Nov 20 '05 #8
Charles,
I didn't mean to suggest that I thought these were the same. Rather than get bogged down in (perhaps) my misunderstandin g, I will state my aim in PDL

For each event that can be raised by an object (sender) Unfortunately I believe you will need to enable the "Option Psychic On"
option, As sender.Events is a secure door, you can only get out what you
know you put in. Which is part of the entire point behind Encapsulation. The
object protects the information that it knows, you need to ask the object
itself for details, if it decides those details are too important not to
share, well its protecting your from yourself...

As I stated, I would expect it to be Nothing or an empty list, is it an
empty list?


I can't tell if it is an empty list because there is no member for
retrieving the length, and none for indexing either.

I thought I saw that EventHandlerLis t implemented IEnumerable, you are
correct it doesn't, so obviously you cannot use it for what you want.
Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:ea******** ******@TK2MSFTN GP10.phx.gbl... Jay
sender.Events is totally different then Delegate.GetInv ocationList.
I didn't mean to suggest that I thought these were the same. Rather than

get bogged down in (perhaps) my misunderstandin g, I will state my aim in PDL

For each event that can be raised by an object (sender)
For each event handler currently attached for the given event
If given event handler is on known target (receiver)
Remove handler
End if
Next event handler
Next event

I don't know how to state it any better than that.
As I stated, I would expect it to be Nothing or an empty list, is it an
empty list?


I can't tell if it is an empty list because there is no member for
retrieving the length, and none for indexing either.

Thanks for your continued help.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:u1******** *******@tk2msft ngp13.phx.gbl.. .
Charles
sender.Events is totally different then Delegate.GetInv ocationList.

Delegate.GetInv ocationList is how you see all the handlers to be called

for
an event.

sender.Events is all the invocationlists for all the events on a

component,
if you designed your component to be used that way. (read its a C# thing).
Incidentally, sender.Events is *not* nothing in my project, and I have

only
called AddHandler to add a handler for an event.

As I stated, I would expect it to be Nothing or an empty list, is it an
empty list?

Hope this helps
Jay

"Charles Law" <bl***@nowhere. com> wrote in message
news:Oz******** ******@TK2MSFTN GP09.phx.gbl...
Jay

I did see once where New Object was used for adding keys, but, as you
suggest that was in a user rolled method.

It seems, from what you are saying, that the invocation list is for user
use
only. I had expected that the 'framework' would have a method - that I

could
get access to - that allowed me to see all the handlers/delegates to
be called for an event. After all, if this is not the case, how does the
framework do it?

When an event is raised, there must be a list somewhere, of delegates

that will be invoked/called. If I could just get access to/enumerate those
handlers, I would be home and dry.

Incidentally, sender.Events is *not* nothing in my project, and I have

only
called AddHandler to add a handler for an event.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> Charles,
> A specific hidden field that the designer of the class supplied when

they
> added the Event to the HandlerList.
>
> I suspect in your project that sender.Events is nothing, or an empty

list.
>
> Generally the class itself will create a key object (via New Object
> literally) that is used to index into the Events collection. If you are > using the Events collection you should know what that key is. In that you
> would have supplied the key to add the event to the collection.
>
> Hope this helps
> Jay
>
>
> "Charles Law" <bl***@nowhere. com> wrote in message
> news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> > Hi Jay
> >
> > Yes, I think that one of those will allow me to test for equality with the
> > receiver. My first hurdle, though is this line:
> >
> > > dlgts = sender.Events.I tem( *WHAT GOES HERE?* ).GetInvocation List() > >
> > Given the sender object, I cannot for the life of me see how to drill down
> > to the invocation list. The Item member seems to need a key in the

shape
> of
> > an object, but what key should I use? I have searched and searched but > > cannot find an example of this anywhere. Can you think what might

work?
> >
> > Thanks.
> >
> > Charles
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in
message
> > news:Om******** ******@tk2msftn gp13.phx.gbl...
> > > Charles,
> > > > For Each dlgt As [Delegate] In dlgts
> > > > If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
> > >
> > > Remember that [Delegate] is short hand for System.Delegate . That
> > > System.Delegate is a class with methods & properties.
> > >
> > > I would start by looking at the methods & properties available
on
the
> > > System.Delegate class.
> > >
> > >
> >
>

http://msdn.microsoft.com/library/de...ClassTopic.asp > > >
> > > Specifically the System.Delegate .Target and System.Delegate Method > > > properties. The System.Delegate .Equals method may or may not help. > > >
> > > Hope this helps
> > > Jay
> > >
> > >
> > > "Charles Law" <bl***@nowhere. com> wrote in message
> > > news:eh******** ******@TK2MSFTN GP09.phx.gbl...
> > > > Mr "yEaH rIgHt" posted the following link about a week ago in

answer
> to
> > my
> > > > question about removing event handlers.
> > > >
> > > > > http://www.vbinfozine.com/t_bindevt.shtml
> > > >
> > > > Following on from that post, the following issues still exist.
> > > >
> > > > The article shows how to find methods on a receiver that match the > > pattern
> > > > OnXXXX given the sender. It loops through the sender events and tries
> to
> > > get
> > > > methods from the receiver that match the pattern. For each one it > finds
> > it
> > > > either adds or removes a handler for the event.
> > > >
> > > > This is great where there is a straight forward mapping, but I

don't
> > have
> > > a
> > > > straight forward mapping. For example, although I could easily use > this
> > > > pattern in many cases, there are situations where the sender has two
> > > similar
> > > > events, only one of which a particular receiver is going to

service.
> > > >
> > > > Let's say that my sender has an event ValueChanged. My
receiver could
> > > easily
> > > > have a method OnValueChanged that could be linked up using the
> technique
> > > > above. As it happens, my receiver has a method
MyControl_Value Changed,
> > but
> > > > this also works with the technique above.
> > > >
> > > > The problem arises where my sender has two values that can change. In
> > this
> > > > case it can raise two events: Value1Changed and Value2Changed. My > > receiver
> > > > only services one of these, and which one is determined at

runtime.
> > > > Therefore, the receiver still has a method MyControl_Value Changed, > > because
> > > > it knows nothing of a sender that has two values.
> > > >
> > > > This breaks the pattern, as there is now easy way to transform the > event
> > > > Value2Changed into the method name MyControl_Value Changed.
> > > >
> > > > So, ...
> > > >
> > > > I am trying to find a way of looping through the sender's events,
as
> > > before,
> > > > but for each one I want to get the invocation list, and see if

my > > receiver
> > > > is in it. Only if it is do I want to remove the handler. I have got
> this
> > > far
> > > >
> > > > <code>
> > > > Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal > > > receiver
> > > > As Object)
> > > >
> > > > Dim SenderType As Type
> > > > Dim ReceiverType As Type
> > > >
> > > > Dim dlgts() As [Delegate]
> > > >
> > > > SenderType = sender.GetType( )
> > > > ReceiverType = receiver.GetTyp e()
> > > >
> > > > For Each ei As EventInfo In SenderType.GetE vents()
> > > >
> > > > ' For each event that the sender can raise, get

the > > invocation
> > > > list
> > > > dlgts = sender.Events.I tem( *WHAT GOES
> > > > HERE?* ).GetInvocation List()
> > > >
> > > > For Each dlgt As [Delegate] In dlgts
> > > > If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
> > > > ei.RemoveEventH andler(sender, dlgt)
> > > > End If
> > > > Next dlgt
> > > >
> > > > Next ei
> > > >
> > > > End Sub
> > > > </code>
> > > >
> > > > Can someone suggest what might replace the capitalised text?
> > > Alternatively,
> > > > can
> > > > anyone think of another way of achieving the same end?
> > > >
> > > > Thanks.
> > > >
> > > > Charles
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #9
Jay

Perhaps we can approach this in another way. I have repeated my original
code below. If I don't use sender.Events - as you have explained why - is
there a way to create a delegate from ei (an EventInfo object)?

If I could create such a delegate (dlgt) , then I could use
dlgt.GetInvocat ionList() instead, and I would be well on my way.

What do you think?

Charles

<code>
Public Shared Sub RemoveHandlers( ByVal sender As Object, ByVal receiver As
Object)

Dim SenderType As Type
Dim ReceiverType As Type

Dim dlgts() As System.Delegate

SenderType = sender.GetType( )
ReceiverType = receiver.GetTyp e()

For Each ei As EventInfo In SenderType.GetE vents()
' For each event that the sender can raise, get the invocation list
dlgts = sender.Events.I tem( *WHAT GOES HERE?* ).GetInvocation List()

For Each dlgt As System.Delegate In dlgts
If *TEST FOR DELEGATE BEING ON RECEIVER?* Then
ei.RemoveEventH andler(sender, dlgt)
End If
Next dlgt
Next ei

End Sub
</code>
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:et******** ******@TK2MSFTN GP10.phx.gbl...
Charles,
I didn't mean to suggest that I thought these were the same. Rather than get
bogged down in (perhaps) my misunderstandin g, I will state my aim in PDL

For each event that can be raised by an object (sender)

Unfortunately I believe you will need to enable the "Option Psychic On"
option, As sender.Events is a secure door, you can only get out what you
know you put in. Which is part of the entire point behind Encapsulation.

The object protects the information that it knows, you need to ask the object
itself for details, if it decides those details are too important not to
share, well its protecting your from yourself...

As I stated, I would expect it to be Nothing or an empty list, is it an empty list?


I can't tell if it is an empty list because there is no member for
retrieving the length, and none for indexing either.

I thought I saw that EventHandlerLis t implemented IEnumerable, you are
correct it doesn't, so obviously you cannot use it for what you want.
Hope this helps
Jay
"Charles Law" <bl***@nowhere. com> wrote in message
news:ea******** ******@TK2MSFTN GP10.phx.gbl...
Jay
sender.Events is totally different then Delegate.GetInv ocationList.


I didn't mean to suggest that I thought these were the same. Rather than

get
bogged down in (perhaps) my misunderstandin g, I will state my aim in PDL

For each event that can be raised by an object (sender)
For each event handler currently attached for the given event
If given event handler is on known target (receiver)
Remove handler
End if
Next event handler
Next event

I don't know how to state it any better than that.
As I stated, I would expect it to be Nothing or an empty list, is it an empty list?


I can't tell if it is an empty list because there is no member for
retrieving the length, and none for indexing either.

Thanks for your continued help.

Charles
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:u1******** *******@tk2msft ngp13.phx.gbl.. .
Charles
sender.Events is totally different then Delegate.GetInv ocationList.

Delegate.GetInv ocationList is how you see all the handlers to be called
for
an event.

sender.Events is all the invocationlists for all the events on a

component,
if you designed your component to be used that way. (read its a C# thing).
> Incidentally, sender.Events is *not* nothing in my project, and I
have only
> called AddHandler to add a handler for an event.
As I stated, I would expect it to be Nothing or an empty list, is it an empty list?

Hope this helps
Jay

"Charles Law" <bl***@nowhere. com> wrote in message
news:Oz******** ******@TK2MSFTN GP09.phx.gbl...
> Jay
>
> I did see once where New Object was used for adding keys, but, as you > suggest that was in a user rolled method.
>
> It seems, from what you are saying, that the invocation list is for

user use
> only. I had expected that the 'framework' would have a method - that I could
> get access to - that allowed me to see all the handlers/delegates to be > called for an event. After all, if this is not the case, how does the > framework do it?
>
> When an event is raised, there must be a list somewhere, of delegates that
> will be invoked/called. If I could just get access to/enumerate
those > handlers, I would be home and dry.
>
> Incidentally, sender.Events is *not* nothing in my project, and I have only
> called AddHandler to add a handler for an event.
>
> Charles
>
>
> "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in

message
> news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> > Charles,
> > A specific hidden field that the designer of the class supplied when they
> > added the Event to the HandlerList.
> >
> > I suspect in your project that sender.Events is nothing, or an empty list.
> >
> > Generally the class itself will create a key object (via New Object > > literally) that is used to index into the Events collection. If you
are
> > using the Events collection you should know what that key is. In that you
> > would have supplied the key to add the event to the collection.
> >
> > Hope this helps
> > Jay
> >
> >
> > "Charles Law" <bl***@nowhere. com> wrote in message
> > news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> > > Hi Jay
> > >
> > > Yes, I think that one of those will allow me to test for
equality with
> the
> > > receiver. My first hurdle, though is this line:
> > >
> > > > dlgts = sender.Events.I tem( *WHAT GOES

HERE?* ).GetInvocation List()
> > >
> > > Given the sender object, I cannot for the life of me see how to

drill
> down
> > > to the invocation list. The Item member seems to need a key in
the shape
> > of
> > > an object, but what key should I use? I have searched and searched but
> > > cannot find an example of this anywhere. Can you think what
might work?
> > >
> > > Thanks.
> > >
> > > Charles
> > >
> > >
> > > "Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in > message
> > > news:Om******** ******@tk2msftn gp13.phx.gbl...
> > > > Charles,
> > > > > For Each dlgt As [Delegate] In dlgts
> > > > > If *TEST FOR DELEGATE BEING ON RECEIVER?* Then > > > >
> > > > Remember that [Delegate] is short hand for System.Delegate . That > > > > System.Delegate is a class with methods & properties.
> > > >
> > > > I would start by looking at the methods & properties available

on the
> > > > System.Delegate class.
> > > >
> > > >
> > >
> >
>

http://msdn.microsoft.com/library/de...ClassTopic.asp
> > > >
> > > > Specifically the System.Delegate .Target and System.Delegate Method > > > > properties. The System.Delegate .Equals method may or may not help. > > > >
> > > > Hope this helps
> > > > Jay
> > > >
> > > >
> > > > "Charles Law" <bl***@nowhere. com> wrote in message
> > > > news:eh******** ******@TK2MSFTN GP09.phx.gbl...
> > > > > Mr "yEaH rIgHt" posted the following link about a week ago in answer
> > to
> > > my
> > > > > question about removing event handlers.
> > > > >
> > > > > > http://www.vbinfozine.com/t_bindevt.shtml
> > > > >
> > > > > Following on from that post, the following issues still exist. > > > > >
> > > > > The article shows how to find methods on a receiver that match the
> > > pattern
> > > > > OnXXXX given the sender. It loops through the sender events and > tries
> > to
> > > > get
> > > > > methods from the receiver that match the pattern. For each
one
it
> > finds
> > > it
> > > > > either adds or removes a handler for the event.
> > > > >
> > > > > This is great where there is a straight forward mapping, but
I don't
> > > have
> > > > a
> > > > > straight forward mapping. For example, although I could easily use
> > this
> > > > > pattern in many cases, there are situations where the sender has two
> > > > similar
> > > > > events, only one of which a particular receiver is going to
service.
> > > > >
> > > > > Let's say that my sender has an event ValueChanged. My receiver > could
> > > > easily
> > > > > have a method OnValueChanged that could be linked up using
the > > technique
> > > > > above. As it happens, my receiver has a method
> MyControl_Value Changed,
> > > but
> > > > > this also works with the technique above.
> > > > >
> > > > > The problem arises where my sender has two values that can

change.
> In
> > > this
> > > > > case it can raise two events: Value1Changed and Value2Changed. My
> > > receiver
> > > > > only services one of these, and which one is determined at
runtime.
> > > > > Therefore, the receiver still has a method

MyControl_Value Changed,
> > > because
> > > > > it knows nothing of a sender that has two values.
> > > > >
> > > > > This breaks the pattern, as there is now easy way to
transform the
> > event
> > > > > Value2Changed into the method name MyControl_Value Changed.
> > > > >
> > > > > So, ...
> > > > >
> > > > > I am trying to find a way of looping through the sender's

events,
as
> > > > before,
> > > > > but for each one I want to get the invocation list, and see
if my
> > > receiver
> > > > > is in it. Only if it is do I want to remove the handler. I

have got
> > this
> > > > far
> > > > >
> > > > > <code>
> > > > > Public Shared Sub RemoveHandlers( ByVal sender As Object,

ByVal
> > > > receiver
> > > > > As Object)
> > > > >
> > > > > Dim SenderType As Type
> > > > > Dim ReceiverType As Type
> > > > >
> > > > > Dim dlgts() As [Delegate]
> > > > >
> > > > > SenderType = sender.GetType( )
> > > > > ReceiverType = receiver.GetTyp e()
> > > > >
> > > > > For Each ei As EventInfo In SenderType.GetE vents()
> > > > >
> > > > > ' For each event that the sender can raise, get the > > > invocation
> > > > > list
> > > > > dlgts = sender.Events.I tem( *WHAT GOES
> > > > > HERE?* ).GetInvocation List()
> > > > >
> > > > > For Each dlgt As [Delegate] In dlgts
> > > > > If *TEST FOR DELEGATE BEING ON RECEIVER?*

Then > > > > > ei.RemoveEventH andler(sender, dlgt)
> > > > > End If
> > > > > Next dlgt
> > > > >
> > > > > Next ei
> > > > >
> > > > > End Sub
> > > > > </code>
> > > > >
> > > > > Can someone suggest what might replace the capitalised text? > > > > Alternatively,
> > > > > can
> > > > > anyone think of another way of achieving the same end?
> > > > >
> > > > > Thanks.
> > > > >
> > > > > Charles
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2134
by: Mark Overstreet | last post by:
I am writing an app that needs to contain an object model that allows it to be controlled similiar to something like Word. However, I am writing this in C# and all managed code. I know that I can use remoting to talk to the UI components but I need an example of how to create an event when something happens on the UI (e.g. text box receives focus) and fire that via my object model back to any remote client. I also need the ability to...
6
1786
by: Charles Law | last post by:
I have a class, which implements an interface. Let's say, that the interface looks something like Public Interface IEventSinks Sub ValueChanged(sender As Object, e As ValueChangedEventArgs) Sub StateUpdated(sender As Object, e As StateUpdatedEventArgs) End Interface In practice, the interface contains many more event handlers like this, but you get the picture.
16
2514
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some of properties or assign event handlers. I need to be able to clone the manipulated control at runtime. I could use the Clone method of some objects (like Font, Style, String,
14
8630
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event handlers are set like the old one. Is there a way to do this job? For example, is there a way to use EventInfo object to get all event handlers of the old control in runtime and set my new cloned control events to the event handlers of the old...
8
36135
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query button on it. If the query returns multiple results, a new window is opened with a grid containing the results. When the user double clicks on the desired row in the grid, I want the first form to populate with the correct data. I don't know how...
10
5617
by: eedarley | last post by:
Is there a way to force the consumer of my object to handle events that I've fired off? I don't care how they handle the event, just that they do. I think in c# there is a way but not sure about vb.net. Please advise.
6
2018
by: Tony Johansson | last post by:
Hello! I know it's possible to have several event handler for a single event but I can't see any point using several event handler for this. I'm probably wrong so can anybody tell me what advantage it might give using several event handler for a single event.
0
9327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9201
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8202
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4564
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2740
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2190
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.