This example shows how a form is invoked modally and how the invoking form is notified which button on the modal form was pressed.
Our sample form which is to be invoked modally has two buttons, Button 1 and Button 2:
The ModalResult value of Button 1 is set to Yes and the ModalResult value of Button 2 is set to No.
The form does not contain any event routines for the two buttons because when either button is clicked, the modal result is set to a value other than None which causes the form to close.
The form that will invoke the other form has a button used to launch the other form. It also has two radio buttons which indicate which button on the invoked form was clicked to close it.
The form to be invoked is included in this form. To do this drag and drop the modal form to the invoking form.
In the invoking form the Click event of the Invoke Modal Form button has logic which sets the radio buttons according to the ModalResult value returned from the invoked form. The ModalResult is returned when the invoked form is closed.
EVTROUTINE HANDLING(#PHBN_1.Click)
*Invoke #MForm modally
invoke #MForm.ShowModalForm
*Test the returned ModalResult
IF COND('#Mform.ModalResult *eq Yes')
set com(#RDBN_1) ButtonChecked(True)
else
set com(#RDBN_2) ButtonChecked(True)
endif
ENDROUTINE
Both forms are saved and complied. The #INVFORM form is executed. When the Invoke Modal Form button is clicked, #MFORM is displayed. #MFORM is closed using either button and #INVFORM shows which button was clicked.
Only push-buttons have the design-time property ModalResult. However, you can programmatically set the form's modal result based on other components. The following code assigns ModalResult Yes if radio button #RDBN_1 is checked when the form is closed and to No if radio button #RDBN_2 is checked when the form is closed:
EVTROUTINE HANDLING(#RDBN_1.Click)
Set Com(#Com_Owner) ModalResult(Yes)
ENDROUTINE
EVTROUTINE HANDLING(#RDBN_2.Click)
Set Com(#Com_Owner) ModalResult(No)
ENDROUTINE