OnQueryUnload Event (AForm)

Occurs before the form window closes.

Syntax

Object.OnQueryUnload ( pbCancel, enUnloadMode )

The OnQueryUnload 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 window should allow to be close. False by default.

enUnloadMode

Val enumAFormUnloadMode

One of the enum constants (below)  indicating the reason for the unload event.

Where

pbCancel can be one of the following:

 

Value

Description

True

Stops the OnQueryUnload event in all loaded forms and stops the form from closing.

False *

Allows the form or application to close.

enumAFormUnloadMode:

 

Name

Value

Description

aformUnloadModeFormControlMenu

0 *

FormControlMenu. The user chooses the Close command from the Control menu on the form.

aformUnloadModeFormCode

1

FormCode. The Unload statement is invoked from code.

aformUnloadModeAppWindows

2

AppWindows. The current Microsoft Windows operating environment session is ending.

aformUnloadModeAppTaskManager

3

AppTaskManager. The Microsoft Windows Task Manager is closing the application.

aformUnloadModeFormMDIForm

4

FormMDIForm. A MDI child form is closing because the MDI form is closing.

Comments

This event allows the user to cancel the closing of a form window.  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 the 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 closing 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 child forms before any of them are unloaded, allowing a child to cancel and leave all the other MDI child windows opened. However, the OnUnload event occurs as each form is unloaded and even if pbCancel is set to True in one of child forms, all the other MDI child forms of which OnUnload events were called previously will be closed .

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 being closed.

Example

The following example shows how to prevent a form from closing its window in its form event OnQueryUnload :

Procedure MyForm.OnQueryUnload(pbCancel, enUnloadMode): Void Public

pbCancel : Var Bool

enUnloadMode: Val enumAFormUnloadMode

{

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

OnUnload, Load Statement, Unload Statement, Loading and Unloading Events