6 13 8 Asking User to Confirm the Closing of a Form

Visual LANSA

6.13.8 Asking User to Confirm the Closing of a Form

If you want to give the user the option of  confirming whether a form should be closed, use the CloseFormQuery method and the CloseQuery event.

Our example has two forms: the main form and a dialog which is displayed when the form is about to be closed. The main form has two buttons, OK and Cancel.

The Cancel button closes the form using the CloseFormQuery method:

Invoke #Com_Owner.CloseFormQuery 
 

In addition to the buttons, the form includes the Dialog form.

The Dialog form has three buttons:

 

All the three buttons have a Click event routine which closes the form:

EVTROUTINE HANDLING(#BTN_CLOSE.Click)

   Invoke #Com_Owner.CloseForm 
ENDROUTINE  

EVTROUTINE HANDLING(#BTN_CANCEL.Click)
   Invoke #Com_Owner.CloseForm
ENDROUTINE  

EVTROUTINE HANDLING(#BTN_MIN.Click)
   Invoke #Com_Owner.CloseForm
ENDROUTINE
 

In addition, they have their ModalResult values set as follows:

     

#BTN_CLOSE

Cancel

 

#BTN_CANCEL

No

 

#BTN_MIN

OK

 

In addition to the Cancel button event routine, the main form has an event routine for the CloseQuery event. This routine invokes the Dialog form and then receives its ModalResult  when the Dialog form is closed. It then tests for the value of the returned ModalResult and performs actions accordingly.

Note that whether the Closing of the form is continued depends on the value of the #Option field which is used for the Continue parameter.

EvtRoutine Handling(#Com_Owner.CloseQuery) Continue(#Option)

   Invoke #Dialog.ShowModalForm

   Define #QResult Reffld(#Std_Texts)
   Change #QResult #Dialog.modalResult 

   Case #QResult
   When '= No'
      Invoke #Com_Owner.RestoreForm
      Set #Option Value(FALSE)
   When '= OK'
      Invoke #Com_Owner.MinimizeForm
      Set #Option Value(FALSE)
   OtherWise  
      Set #Option Value(TRUE)
   EndCase  
EndRoutine  

 

The case statement restores the main form if the ModalResult value returned from the Dialog form is No (assigned to the Cancel button) and minimizes the main form if the value returned is OK (assigned to the Minimize button). In both cases the Continue parameter is set to False. If any other ModalResult value is returned,  the form is closed.

Ý 6.13 Forms