E
edamron
I'm going through a web cast series and have discovered that I have a
profound lack of understanding when it comes to the scope of object
created in the Load Sub of forms. The instructor creates many objects
in the Load event handler. However isn't it true that when the Load
sub exits these object will be destroyed?? I don't see how what he is
doing can possibly work. Below is the Load handler. Please notice
that although he creates the objects he doesn't do anything with them
so what's the point? Thanks in advance.
Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.controller = New UIControl()
'**
'** hookup handlers for events raised by controller
'**
AddHandler controller.ExitTheApp, AddressOf Me.FormMain_Exit
AddHandler controller.ShowSalaryUI, AddressOf Me.ShowSalaryUI
AddHandler controller.HideSalaryUI, AddressOf Me.HideSalaryUI
AddHandler controller.EmptyTextField, AddressOf Me.InvalidName
AddHandler controller.ClearEmployeeInfo, AddressOf
Me.ClearEmployeeInfo
AddHandler controller.UpdateEmployeeInfo, AddressOf
Me.UpdateContactInfoTabPage
AddHandler controller.UpdateEmployeeInfo, AddressOf
Me.UpdateHomeAddrTabPage
'** File >> Show/Hide:
Dim toggleMenuAdapter As ToggleMenuItemAdapter
toggleMenuAdapter = New
ToggleMenuItemAdapter(Me.ShowSalaryToolStripMenuItem, _
New SimpleCommand(AddressOf controller.ShowSalaryTabPage),
_
New SimpleCommand(AddressOf controller.HideSalaryTabPage))
'** File >> Exit:
Dim menuAdapter As MenuItemAdapter
menuAdapter = New MenuItemAdapter(Me.ExitToolStripMenuItem, _
New SimpleCommand(AddressOf controller.ExitApp))
'** cmdLookup Click:
Dim lookupAdapter As LookupAdapter
lookupAdapter = New LookupAdapter(Me.cmdLookup, _
me.txtFirstName, me.txtLastName, New
LookupCommand(AddressOf controller.Lookup))
'** TextBox Validating:
Dim textboxValidatingAdapter As TextBoxValidatingAdapter
Dim validatingCmd As ValidatingCommand
validatingCmd = New ValidatingCommand(AddressOf
controller.NonEmpty_Validating)
textboxValidatingAdapter = New
TextBoxValidatingAdapter(Me.txtFirstName, validatingCmd)
textboxValidatingAdapter = New
TextBoxValidatingAdapter(Me.txtLastName, validatingCmd)
End Sub
profound lack of understanding when it comes to the scope of object
created in the Load Sub of forms. The instructor creates many objects
in the Load event handler. However isn't it true that when the Load
sub exits these object will be destroyed?? I don't see how what he is
doing can possibly work. Below is the Load handler. Please notice
that although he creates the objects he doesn't do anything with them
so what's the point? Thanks in advance.
Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.controller = New UIControl()
'**
'** hookup handlers for events raised by controller
'**
AddHandler controller.ExitTheApp, AddressOf Me.FormMain_Exit
AddHandler controller.ShowSalaryUI, AddressOf Me.ShowSalaryUI
AddHandler controller.HideSalaryUI, AddressOf Me.HideSalaryUI
AddHandler controller.EmptyTextField, AddressOf Me.InvalidName
AddHandler controller.ClearEmployeeInfo, AddressOf
Me.ClearEmployeeInfo
AddHandler controller.UpdateEmployeeInfo, AddressOf
Me.UpdateContactInfoTabPage
AddHandler controller.UpdateEmployeeInfo, AddressOf
Me.UpdateHomeAddrTabPage
'** File >> Show/Hide:
Dim toggleMenuAdapter As ToggleMenuItemAdapter
toggleMenuAdapter = New
ToggleMenuItemAdapter(Me.ShowSalaryToolStripMenuItem, _
New SimpleCommand(AddressOf controller.ShowSalaryTabPage),
_
New SimpleCommand(AddressOf controller.HideSalaryTabPage))
'** File >> Exit:
Dim menuAdapter As MenuItemAdapter
menuAdapter = New MenuItemAdapter(Me.ExitToolStripMenuItem, _
New SimpleCommand(AddressOf controller.ExitApp))
'** cmdLookup Click:
Dim lookupAdapter As LookupAdapter
lookupAdapter = New LookupAdapter(Me.cmdLookup, _
me.txtFirstName, me.txtLastName, New
LookupCommand(AddressOf controller.Lookup))
'** TextBox Validating:
Dim textboxValidatingAdapter As TextBoxValidatingAdapter
Dim validatingCmd As ValidatingCommand
validatingCmd = New ValidatingCommand(AddressOf
controller.NonEmpty_Validating)
textboxValidatingAdapter = New
TextBoxValidatingAdapter(Me.txtFirstName, validatingCmd)
textboxValidatingAdapter = New
TextBoxValidatingAdapter(Me.txtLastName, validatingCmd)
End Sub