G
Giovanni Bassi
Hello All,
I have encountered a problem.
I am using visual inheritance and my base form adds an event handler on Form
Load using the AddHandler Keyword.
The problem is that if the Event Handler code is there, when I create the
inherited form I get the error "Object Reference not set to an instance of
an object". If it is not I get no error.
I have tried leaving this code in the forms Sub New, but it produces the
same error.
I need the handler to be added during the form load and removed on the form
unload. I cannot use the withevents keyword because the class is declared on
the global level, and it is actually a property of this globally declared
class. Some code to help:
-//-
On a global Module:
Friend g_objTables As TableOps
On the application's Sub Main:
g_objTables = New TableOps(AppSettings.ConnectionString)
On the Base Class:
Private Sub frmBase1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddHandler m_btObj.DataChanged, AddressOf CostCentersDataChanged
AddHandler m_btObj.Range.RangeChanged, AddressOf RangeChanged
End Sub
Private Sub CostCentersDataChanged() 'handling DataChanged Event
'various steps taken to handle the event
End Sub
Private Sub RangeChanged()
'various steps taken to handle the event
End Sub
Private Sub frmBase1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
RemoveHandler m_btObj.DataChanged, AddressOf CostCentersDataChanged
RemoveHandler m_btObj.Range.RangeChanged, AddressOf RangeChanged
End Sub
On the Derived Class:
Private Sub frmCostCenters_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
m_btObj = g_objTables.CostCenters
End Sub
-//-
If I comment the two code lines in frmBase1_Load I get no error. If I
don't...
Also, if I try calling something else, like Msgbox("Test"), it works fine.
Does anyone know why that's happening? Can't I add event handlers in the
Form Load?
Thanks a lot in advance for all the replies.
Giovanni Bassi
I have encountered a problem.
I am using visual inheritance and my base form adds an event handler on Form
Load using the AddHandler Keyword.
The problem is that if the Event Handler code is there, when I create the
inherited form I get the error "Object Reference not set to an instance of
an object". If it is not I get no error.
I have tried leaving this code in the forms Sub New, but it produces the
same error.
I need the handler to be added during the form load and removed on the form
unload. I cannot use the withevents keyword because the class is declared on
the global level, and it is actually a property of this globally declared
class. Some code to help:
-//-
On a global Module:
Friend g_objTables As TableOps
On the application's Sub Main:
g_objTables = New TableOps(AppSettings.ConnectionString)
On the Base Class:
Private Sub frmBase1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddHandler m_btObj.DataChanged, AddressOf CostCentersDataChanged
AddHandler m_btObj.Range.RangeChanged, AddressOf RangeChanged
End Sub
Private Sub CostCentersDataChanged() 'handling DataChanged Event
'various steps taken to handle the event
End Sub
Private Sub RangeChanged()
'various steps taken to handle the event
End Sub
Private Sub frmBase1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
RemoveHandler m_btObj.DataChanged, AddressOf CostCentersDataChanged
RemoveHandler m_btObj.Range.RangeChanged, AddressOf RangeChanged
End Sub
On the Derived Class:
Private Sub frmCostCenters_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
m_btObj = g_objTables.CostCenters
End Sub
-//-
If I comment the two code lines in frmBase1_Load I get no error. If I
don't...
Also, if I try calling something else, like Msgbox("Test"), it works fine.
Does anyone know why that's happening? Can't I add event handlers in the
Form Load?
Thanks a lot in advance for all the replies.
Giovanni Bassi