what is wrong with this removehandler..?

  • Thread starter Thread starter GS
  • Start date Start date
G

GS

RemoveHandler MyBase.DocumentCompleted, AddressOf Me.myDocumentCompleted

Warning 27 The 'AddressOf' expression has no effect in this context because
the method argument to 'AddressOf' requires a relaxed conversion to the
delegate type of the event. Assign the 'AddressOf' expression to a variable,
and use the variable to add or remove the method as the handler.
D:\_doc\Fce\My Documents\Visual Studio
2008\Projects\webCtlExtended\webCtlExtended\webCtlExt.vb 68 49
webCtlExtended

when I tried
RemoveHandler MyBase.DocumentCompleted, Me.myDocumentCompleted
I get "Expression does not produce a value." with myDocumentCompleted being
underlined

I tried also
RemoveEvtHandler(myDocumentCompleted)
Sub RemoveEvtHandler(ByVal e As EventHandler)
RemoveHandler MyBase.DocumentCompleted, e
End Sub

I get error complaining the "removeEvtHandler(myDocumentCompleted)"
Error 27 Expression does not produce a value. D:\_doc\Fce\My
Documents\Visual Studio
2008\Projects\webCtlExtended\webCtlExtended\webCtlExt.vb 68 26
webCtlExtended
Error 27 Expression does not produce a value. D:\_doc\Fce\My
Documents\Visual Studio
2008\Projects\webCtlExtended\webCtlExtended\webCtlExt.vb 68 26
webCtlExtended




your help is much appreciated
 
thx

RemoveEvtHandler(AddressOf myDocumentCompleted)
together with
Sub RemoveEvtHandler(ByVal e As WebBrowserDocumentCompletedEventHandler)
RemoveHandler MyBase.DocumentCompleted, e
End Sub
works
but

RemoveHandler MyBase.DocumentCompleted, AddressOf myDocumentCompleted
stilll does not.
that is a pain.

on the surface C# seems a bit easier with event handler and delegates
 
Hi, I think I understand why it behaves how it behaves.
A new feature of VB9 allows you to AddHandler for methods with slightly
different signatures than signature of event is. However as I understand it
some hidden routing method/delegate (which routes event to method with
different signature) is created in compile time. And when you uses
RemoveHandler another one is created which results to RemoveHandler removing
handler which had been never attached. So, nothing happens and handler
attached via AddHanlder is still attached.
There are two ways how to prevent this behavior:
1) Is prior VB9 - ensure that method (handler) as EXACTLY same signature as
event (event delegate)
2) Add handler is some way like this
Dim HadlerDelegate = AddressOf MyMethod
AddHandler TheObject.Event, HandlerDelegate
then store HandlerDelegate somewhere and use it with RemoveHandler.
 
Hi, I think I understand why it behaves how it behaves.
A new feature of VB9 allows you to AddHandler for methods with slightly
different signatures than signature of event is. However as I understand it
some hidden routing method/delegate (which routes event to method with
different signature) is created in compile time. And when you uses
RemoveHandler another one is created which results to RemoveHandler removing
handler which had been never attached. So, nothing happens and handler
attached via AddHanlder is still attached.
There are two ways how to prevent this behavior:
1) Is prior VB9 - ensure that method (handler) as EXACTLY same signature as
event (event delegate)
2) Add handler is some way like this
Dim HadlerDelegate = AddressOf MyMethod
AddHandler TheObject.Event, HandlerDelegate
then store HandlerDelegate somewhere and use it with RemoveHandler.
 
Back
Top