Collection (hashtable) of objects that raise events

J

Jason L James

Hi All,

I have a class (class 1) that raises a couple of events.

I also have another class (class 2) that contains a hashtable
of objects that are of type class 1.

Is there anyway of trapping the events raised by one
of the objects in the hashtable in class 2 and processing
the event in class 2?

Many thanks,

Jason.
 
C

Cor Ligthert

Jason,

I don't see the problem as a sample (not a hashtable) roughly typed in this
message

\\\
Public class1
public sub new
dim obj2 as new class2
addhandler obj2.theEvent, AddressOf bla_Event
end sub
public sub bla_Event()
'do what you want
end sub
end class
Public class2
Public sub new
public event theEvent()
public tim as new timer
tim.enabled = true
tim.interval = 1000
addhandler obj2.theEvent, AddressOf bla_Event
end sub
public sub bla_Event
raise theEvent
end sub
////

I hope this helps?

Cor
 
H

Herfried K. Wagner [MVP]

Jason,

Jason L James said:
I have a class (class 1) that raises a couple of events.

I also have another class (class 2) that contains a hashtable
of objects that are of type class 1.

Is there anyway of trapping the events raised by one
of the objects in the hashtable in class 2 and processing
the event in class 2?

You can add a common handler for 'class1''s event using 'AddHandler' for
each instance of 'class1'. The event handler's 'sender' parameter will
contain a reference to the object that raised the event. 'RemoveHandler'
can be used to remove a handler.
 
J

Jason L James

Thanks Guys, I'll give it a go.

Jason.

Jason,



You can add a common handler for 'class1''s event using 'AddHandler' for
each instance of 'class1'. The event handler's 'sender' parameter will
contain a reference to the object that raised the event. 'RemoveHandler'
can be used to remove a handler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top