Delegate Problem: Object Reference not set to an instance of an Object
Posted on 2006-05-16
I am building a custom listbox control and I need to send notification to one control, from another when the Mouse Wheel is used.
I am new to delegates but I thought I had understood them this way:
If Class A needs to tell Class B the mouse wheel was used then...
protected m_Notify As OnThisMouseWheel
Public Delegate Sub OnThisMouseWheel(Str)
Public Sub NotifyOnMouseWheel(ByVal value As OnThisMouseWheel)
m_Notify = value
Private Sub MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ...
Catch ex As Exception
Private Sub AddItem(ByVal ob As CustomControl)
ob.NotifyOnMouseWheel(New CustomControl.OnThisMouseWheel(AddressOf NotifyMe))
Public Sub NotifyMe(ByVal s As String)
If I invoke m_Notify from NotifyOnMouseWheel in Class A right after assigning it, then it works. The object assignment is working and the delegate communicates to the other control. But after that the m_Notify variable equals Nothing. I Imagine it has something to do with the Subroutine that sets up the controls and creates the delegate but I've tried a couple different ways to pass the variable and I still get the same result. Is this thread related?
It is rather urgent so high points.