Michael,
| OK, given that I can't force an event handler to be used, what is the
syntax
| to do the following:
Dim anObject As New Something(AddressOf RequiredExternalHandler)
Where:
Class Something
Public Delegate Sub EventHandler(ByVal parms As Object)
Event OptionalEvent As EventHandler
Event RequiredEvent As EventHandler
Public Sub New(ByVal handler As EventHandler)
AddHandler RequiredEvent, handler
End Sub
End Class
Public Sub RequiredExternalHandler(ByVal parms As Object)
End Sub
Note Event handlers cannot be functions. You can change the "Delegate Sub
EventHandler" to include the correct parameters as needed.
I normally use System.EventHandler rather then define my own, unless I need
a specific type derived from EventArgs.
Using:
Event OptionalEvent As EventHandler
Event RequiredEvent As EventHandler
Instead of:
| > Public Event OptionEvent(ByVal e As System.EventArgs)
| > Public Event RequiredEvent(ByVal e As System.EventArgs)
Is generally better as the first uses a predefined delegate (EventHandler)
where as the second will create a hidden delegate for each event that you
define, seeing as the events have the signuture you are getting a number of
identical duplicate types defined in your assembly...
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:u0*************@tk2msftngp13.phx.gbl...
| OK, given that I can't force an event handler to be used, what is the
syntax
| to do the following:
|
| dim MyClass as new MyObject(requiredexternalhandler)
|
| where
|
| Public Function RequiredExternalHandler(byval unhandledvalue as string) as
| string
| end function
|
| Basically I have a class that is using application specific login (uses
the
| integrated windows login most of the time), but when it fails, it needs to
| call a platform specific login hander. The platforms are
| ConsoleApplication, Windows Forms Application, and ASPNet Application.
|
| Thanks,
| Mike.
|
|
| "Greg Burns" <bl*******@newsgroups.nospam> wrote in message
| news:eG*************@TK2MSFTNGP14.phx.gbl...
| > Can't you do something using implemention inheritance? Not my strongest
| > skill, so I not sure how you "require" that a class implement another.
| >
| > Public Interface IRequiredEvent
| > Event RequiredEvent(ByVal e As EventArgs)
| > End Interface
| >
| > Public Class Class1
| > Implements IRequiredEvent
| > Public Event OptionEvent(ByVal e As System.EventArgs)
| > Public Event RequiredEvent(ByVal e As System.EventArgs) Implements
| > IRequiredEvent.RequiredEvent
| > End Class
| >
| > Public Class Class2
| > Implements IRequiredEvent
| > Public Event RequiredEvent(ByVal e As System.EventArgs) Implements
| > IRequiredEvent.RequiredEvent
| > End Class
| >
| > Greg
| >
| >
| > "Marina" <so*****@nospam.com> wrote in message
| > news:eT**************@TK2MSFTNGP09.phx.gbl...
| > > No, you cannot require that a program handle the event of a particular
| > > component or control.
| > >
| > > "Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
| > > news:%2****************@TK2MSFTNGP10.phx.gbl...
| > >> Is there anyway to raise an event from a class and require that any
| > >> program
| > >> using that class (not just inheritance) have an event handler for
| > >> specific
| > >> events in the class? In my case, some events don't need to be
handled,
| > >> but
| > >> some must be handled by the program that uses the class.
| > >>
| > >> I'm looking for something along the lines of
| > >>
| > >> Class MyClass
| > >> Event OptionalEvent(parms)
| > >> Event RequiredEvent(parms)
| > >>
| > >> end Class
| > >>
| > >> Mike Ober.
| > >>
| > >>
| > >>
| > >>
| > >
| > >
| >
| >
| >
|
|
|