OnUnload Event (AForm)

Occurs when a form is about to be removed from the screen.

Syntax

Object.OnUnload ( pbCancel )

The OnUnload event syntax has the following parts:

 

Name

Type

Description

Object

AForm

AForm object

pbCancel

Var Bool

A boolean value that is set by the event and  specifies whether or not  the form will be removed. False by default.

Where

pbCancel can be one of the following:

 

Value

Description

True

The form will be prevented from being removed.

False *

The form will be removed.

Comments

This event allows the user to cancel the closing of a form window before the form is ready to be removed. For example, if a user has not yet saved some new data in the form, the form can prompt the user to save the data or cancel closing of the form.

This event is triggered as a result of using the Unload statement or the close box on the form caption or when the application is about to be closed (e.g. exiting Windows). The event is not triggered as a result of setting the form variable to 'Nothing'. You can use either the OnQueryUnload or OnUnload event procedure to set the pbCancel parameter to True, stopping the unloading process.

When a MDI form object closes, the OnQueryUnload event occurs first for the MDI form and then in all its MDI child forms. If no form cancels the OnQueryUnload event, the OnUnload event occurs first in all other child forms and then in the MDI form.

For MDI child forms, the OnQueryUnload event occurs in all forms before any of them are unloaded, allowing a child to cancel and leave all the other MDI child windows opened. The OnUnload event occurs as each form is unloaded and the other MDI child forms of which OnUnload events were previously called will be closed even if pbCancel is set to True.

Unloading a form causes all other Normal (not MDI Child forms) forms whose parent (owner) is set to the form to be closed as well. These forms will not receive the OnQueryUnload event before closed. When the form is reloaded, the contents of all its controls are reinitialized.

The OnQueryUnload event occurs before the OnUnload event. The OnUnload event occurs before the OnTerminate event.

Example

The following example shows the cancelling the unloading process in the form event OnUnload :

Procedure MyForm.OnUnload(pbCancel): Void Public

pbCancel : Var Bool

{

if bModified

! confirm the user

enMsgBoxId=MsgBox("Do you want to save the changes?", aMsgYesNoCancel)

select enMsgBoxId

case aIdYes

! save ...

case aIdNo

! do not save

case aIdCancel

pbCancel=TRUE       ! cancelling the unloading processs

endselect

endif

}

Applies to

AForm

See Also

OnLoad, OnQueryUnload, OnTerminate, Load Statement, Unload Statement, Loading and Unloading Events