By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Check if object handles/is hooked up to a certain type of event/event handler

P: n/a
Is there a way to check if an object handles a certain type of event or
if the object is hooked up to a certain event handler/call back
function?

For instance what would be the equivalent syntax in the following:

Private x as Object
Public Event TestEvent()

Sub Y()
if (x handles TestEvent) then Write("X Handles TestEvent()")
End Sub

-----------------------------------------------------------------

Private x as Object
Public Event TestEvent()

Sub New()
AddHandler x, AddressOf XHandlerFunction
End Sub

Sub XHandlerFunction()
' handling code
End Sub

Sub CheckHookup()
' Consider multiple handlers
If x.handlers(0) Is XHandlerFunction Then
Write("X has XHandlerFunction() as one of its handlers")
End If
End Sub

----------------------------------------------------------------

Thank you for any help with thi

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


nf***@vizual.co.uk wrote:
Is there a way to check if an object handles a certain type of event or
if the object is hooked up to a certain event handler/call back
function?


Yes. When you write

Public Event TestEvent()

then behind the scenes two things get created: a delegate class named
TestEventEventHandler, and an instance of this class, named
TestEventEvent. Then, TestEventEvent.GetInvocationList is an array of
Delegate, which contains all the handlers hooked to that event. There
is no difference in the treatment of an event with one handler and one
with many handlers.

To examine the invocation list:

Dim d as TestEventEventHandler
for each d in TestEventEvent
if d Is X Then
'... X is hooked to this event
end if
next

--
Larry Lard
Replies to group please

Nov 21 '05 #2

P: n/a
Thank you very much for your help. Most appreciated.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.