OnCloseModalDialog - cWebBaseUIObject

Sent by a modal dialog to its invoking object when the dialog closes

Type: Event

Parameters: Handle hoModalDialog

ParameterDescription
hoModalDialogHandle of modal dialog object


Syntax
Procedure OnCloseModalDialog Handle hoModalDialog

Description

The OnCloseModalDialog event is the default event sent by a modal dialog (cWebModalDialog) to its invoking object when the modal dialog is closed.

You would implement an OnCloseModalDialog event handler inside the object that activates (invokes) a modal dialog, i.e. the object that sends the Popup message to a modal dialog. When the modal dialog is closed, it will send OnCloseModalDialog back to the invoking object. A handle to the modal dialog that was closed is passed as the hoModalDialog parameter.

By default, the modal dialog only sends OnCloseModalDialog if it was closed via the OK message (i.e. the Ok button was clicked or the [Enter] key was pressed by the user). If the modal dialog is closed via the Cancel message (i.e. the "X" or close button was clicked or the ESC key was pressed by the user), then OnCloseModalDialog is not sent by default.

To enable the OnCloseModalDialog event when the modal dialog is closed via the Cancel message. you must set the pbServerOnEscape property, of the modal dialog to True.

You can override the message that is sent when the dialog closes by setting the psReturnMessage property of the modal dialog. This means that the named message will be sent when the dialog closes, instead of OnCloseModalDialog.

You can override the target object that receives the OnCloseModalDialog event by setting the psReturnObject property of the modal dialog. This means that the named object will receive OnCloseModalDialog instead of the invoking object.

Sample

Object oWebCalculator is a cWebModalDialog
    Set piWidth to 300
    Set piHeight to 125
    Set pbResizable to False
    Set psCaption to "Web Calculator"
    Set piColumnCount to 2

    Object oNum1 is a cWebForm
        Set peDataType to typeNumber
        Set piPrecision to 4
        Set psLabel to "First Number"
        Set piColumnSpan to 0
    End_Object

    Object oNum2 is a cWebForm
        Set peDataType to typeNumber
        Set piPrecision to 4
        Set psLabel to "Second Number"
        Set piColumnSpan to 0
    End_Object

    Object oOkButton is a cWebButton
        Set psCaption to C_$OK
        Set piColumnIndex to 0

        Procedure OnClick
            Send Ok
        End_Procedure
    End_Object 

    Object oCancelButton is a cWebButton
        Set psCaption to C_$Cancel
        Set piColumnIndex to 1

        Procedure OnClick
            Send Cancel
        End_Procedure
    End_Object 

    // used to initialize the dialog
    Procedure Popup
        WebSet psValue of oNum1 to 0
        WebSet psValue of oNum2 to 0
        Forward Send Popup
    End_Procedure

    Procedure OnSubmit
        Send Ok
    End_Procedure

    // After completion, call this from the invoking object 
    // to get data from the dialog 
    Procedure GetResultValues Number ByRef N1 Number ByRef N2 Number ByRef nTotal
        WebGet psValue of oNum1 to N1
        WebGet psValue of oNum2 to N2
        Move (N1 + N2) to nTotal
    End_Procedure
End_Object

The above example demonstrates a simple calculator dialog that allows the input of two numbers and adds them together. Two web forms are used to enter the numbers and two buttons are used to close the dialog.

The dialog is activated by sending Popup. The oOkButton sends the OK message and the oCancelButton sends the Cancel message. Both messages will close the dialog, but the state of the pbCanceled property is set to True or False, accordingly.

When the dialog is closed via the OK message, then it will send OnCloseModalDialog to the object that invoked it (via Popup).

This dialog would be used from an invoking object in some other view in the following way:

Object oCalcButton is a cWebButton
    Set psCaption to "Calculate"

    Procedure OnClick
        Send Popup of oWebCalculator (Self)
    End_Procedure

    // standard callback method when modal dialog is invoked using Popup 
    Procedure OnCloseModalDialog Handle hoModalDialog
        Number n1 n2 nTotal
        // assume that this function no longer returns bCanceled.     
        Send GetResultValues of hoModalDialog (&n1) (&n2) (&nTotal)
        Send ShowInfoBox (String(n1) + "+" + String(n2) + "=" + String(nTotal)) "Calculation Complete"            
    End_Procedure
End_Object

The resulting addition is retrieved by calling GetResultValues.