queryUnload

queryUnload(cancel: Integer io;
            reason: Integer);

The queryUnload event occurs before a form closes, to give the logic the opportunity to reject the closure. Logic dealing with the closure should be placed in the unload event. When the MDI frame is closed, this event is sent to all child forms as well as the MDI frame. This event is not called if a form is unloaded before it was displayed and the load event has not been executed, or if the delete method was used to delete the running instance of the form.

When the JADE language terminate instruction is executed, all active forms have the queryUnload event sent to them.

If a queryUnload method is aborted, queryUnload is not called for any other forms affected by the unload and all affected forms are unloaded without calling the unload method. If an unload method is aborted, all other affected forms are unloaded without calling the unload method.

If any form involved in the close process rejects the request to unload, no further queryUnload events are sent and no form unloads are performed. When all forms involved in the closure agree to close (by the queryUnload events), the unload event is then sent to those forms.

If the form to which the event is sent is the active form, a lostFocus event is caused on the active control before the queryUnload event is sent. If the queryUnload event is rejected, focus is returned to that same control, unless the focus has been moved elsewhere in the processing of that event.

When the last MDI child form in the default MDI frame closes (supplied by the jade.exe program), the default MDI frame also closes. When the last form closes, the application closes.

The parameters of the queryUnload event are listed in the following table.

Parameter Description
cancel Setting this parameter to any value other than 0 (zero) stops the queryUnload event in all loaded forms and stops the form and application from closing. This parameter is ignored if the form database object was deleted.
reason Indicates the reason for the queryUnload event.

The reason parameter can have the values listed in the following table.

Form Class Constant Value Description
QueryUnload_MdiChild 4 An MDI child form is closing because the MDI form is closing.
QueryUnload_TaskManager 3 The Microsoft Windows Task Manager is closing the application.
QueryUnload_UnloadMethod 1 The unload event has been invoked from logic.
QueryUnload_User 0 The user has selected the Close command from the Control‑Menu icon on the form.
QueryUnload_Windows 2 The current Windows-environment session is ending.

Use the queryUnload event to ensure that there are no unfinished tasks in each form before an application closes. For example, if a user has not yet saved some new data in any form, your application can ask the user if the data should be saved.