Among many form events, some of events are associated with Loading and Unloading a form. They are called in the order after Load (a form) statement is executed or prior to Unload (a form) statement is evoked. They are important events for programming with forms.
These are events called in the order during loading a form. For more detailed information, refer to its reference pages:
OnInitialize() - it is called after the form object is created but before its window or any of the form controls or menus are created. It is the first event that occurs to the form after Load statement.
OnActivate() - Occurs when the form becomes the active window.
OnLoad() - Occurs when a form is loaded after its controls and menus are created. Typically, you use OnLoad event procedure to include initialization code for a form and its controls and menus.
OnResize() - Occurs when a form is first displayed. Use this event procedure to move or resize controls.
These are events called in the order during unloading a form:
OnQueryUnLoad() - Occurs before a form object closes. This event is to give the user a chance to confirm the unloading the form by setting its parameter pbCancel to True.
OnUnload() - Occurs when a form is about to be removed from the screen. Typically cleaning up and exiting processes will be performed. Again you can cancel the unloading by setting the parameter pbCancel to True.
OnTerminate() - Occurs when all references to an instance of a form object are removed from memory by setting all the variables that refer to the form object to Nothing or when the last reference to the form object falls out of scope.
The following examples are used in ATEasy TestExec driver and Profile driver:
Procedure formTestExec.OnInitialize(): Void Public Compile ! Occurs when the form is created before controls are created.
-------------------------------------------------------------------------
{
! set help file path
form.HelpFile=driver.m_stData.sHelpFile
}
Procedure formCustomizeAndUsers.OnLoad(): Void Public Compile ! Occurs when a form is loaded after controls are created.
-------------------------------------------------------------------------
{
! init form variables
f_vUserGroups=m_stData.stUsersSettings.vUserGroups
f_vCommands=m_stData.vCommands
f_vLogFilesOptions=m_stData.vLogFilesOptions
! only load first page of ATab control, 'tabUsers'
if NOT IsMultiUser()
tabUsers.Pages("pageGroups").Visible=False
tabUsers.Pages("pageUsers").Visible=False
form.Caption="Customize"
LoadPageCommands()
else
LoadPageGroups()
endif
! activate first page
tabUsers.ActivatePage(0)
}
Procedure ProfileEditorForm.OnResize(): Void Public Compile ! Occurs when a form is first displayed or when the window state of a form changes.
-------------------------------------------------------------------------
...
... ! variable declarations
{
! do nothing if window is not visible (i.e. during form load)
if NOT Form.Visible Then return
! remember the normal window state size
if WindowState=aformWindowStateNormal
SaveWindowPosition()
endif
! width
lWidth=ScaleWidth()
iAddButtonWidth=lWidth*14/100 ! 14%
iGap=lWidth*1.5/100 ! 1.5%
iTreeViewWidth=(lWidth-iAddButtonWidth-(iGap*4))/2
...
}
Procedure formTestExec.OnQueryUnload(pbCancel, enUnloadMode): Void Public Compile ! Occurs before the object closes.
-------------------------------------------------------------------------
pbCancel: Var Bool
enUnloadMode: Val Internal.enumAFormUnloadMode
{
! if running, do not allow to Unload form
if (m_stRunTime.enFlags and ateStart) and (enUnloadMode<>aformUnloadModeFormCode)
pbCancel=TRUE
endif
}
Procedure formTestExec.OnUnload(pbCancel): Void Public Compile ! Occurs when a form is about to be removed from the screen.
-------------------------------------------------------------------------
pbCancel: Var Bool
{
SaveWindowPosition()
! maintenance log files
CheckMaintenanceLogFiles(ateMaintenanceUponExit)
! save current setting (window position, last program, options etc...)
SaveCurrentSetting()
m_stRunTime.enFlags=0
m_stRunTime.bWait=False
UnloadLogWindows()
Driver Utility Message Close()
Internal.SetLogOff()
! call procedure ExitApp instead of Exit EndEvents to avoid calling OnEndProgram events again
ExitApp()
}