Boni wrote:
Dear all,
is it not possible to have shred events?
I think it is.
error BC30600: 'WithEvents' variable does not raise any instance events that
are accessible to 'Class A."
The error message is actually useful here. If you declare an object
*variable* WithEvents, that means that it is going to hold an
*instance* of that class, so there must be *instance* events for it to
listen for. cMyEvents doesn't have any *instance* events so object
variables of type cMyEvents will never receive any events, so can't be
declared WithEvents.
That make sense? :)
Your event class definition is fine:
Class cMyEvents
Public Shared Event MyStarEvent()
Shared Sub Raisestart()
RaiseEvent MyStarEvent()
End Sub
End Class
So now we have defined a shared event, cMyEvents.MyStarEvent. We just
need to set up a handler, so let's try:
Friend Class A
Public Shared Sub HandleStarEvent() Handles cMyEvents.MyStarEvent
End Sub
End Class
But this doesn't compile - it seems that 'Handles', like 'WithEvents',
is only to be used for *instance* event handling. But we are not done
yet! Now we try:
Friend Class A
Public Shared Sub HandleStarEvent()
End Sub
Public Shared Sub StartListening()
AddHandler cMyEvents.MyStarEvent, AddressOf HandleStarEvent
End Sub
End Class
and this works! You must of course remember to call StartListening at
some point :)
--
Larry Lard
Replies to group please