PreviousNextIndex

WAIT-FOR statement (.NET and ABL)


(Windows only; GUI for .NET only)

This WAIT-FOR statement instructs the AVM to stop executing the current block and remain in a wait state (blocking) until a .NET method that it calls returns. The AVM continues to respond to all incoming ABL events (see the WAIT-FOR statement (ABL only) reference entry) as well as .NET events, and it executes any associated triggers, event procedures, or .NET event handlers while in this wait state.

Note: ABL supports a separate version of the WAIT-FOR statement (ABL WAIT-FOR) that blocks only for ABL events. For more information, see the WAIT-FOR statement (ABL only) reference entry.
Syntax

WAIT-FOR { object-reference | type-name } : method-name ( [ parameters ] ) 
  [ SET return-value ]  

object-reference
type-name
method-name
parameters
SET return-value

For more information on .NET input-blocking methods that you can call in the WAIT-FOR statement, see the notes of this reference entry.

Example

The ABL-derived .NET class, r-WaitForms, inherits the Progress.Windows.Form class to implement a non-modal .NET form. When you try to close the displayed form, a dialog box appears that prompts if you want the form to complete closing or not. If you choose to complete closing, the form closes. If you choose to cancel the closing, the form remains displayed, and you can try to close the form, again.

When you instantiate r-WaitForms, it initializes and subscribes a handler (the Form_Closing( ) method) to the FormClosing event of the form. You can then display the form by calling the DoWait( ) method on the r-WaitForms instance. This method executes the WAIT-FOR statement, which calls the .NET input-blocking method System.Windows.Forms.Application:Run( ). (For more information on this method, see the notes.) When you try to close the displayed form, this causes the non-modal form to publish its FormClosing event, which executes the Form_Closing( ) method to handle the event.

r-WaitForms.cls
USING System.Windows.Forms.* FROM ASSEMBLY. 
USING Progress.Util.*        FROM ASSEMBLY. 
CLASS r-WaitForms INHERITS Progress.Windows.Form: 
  DEFINE VARIABLE rFormDescr AS CLASS Label NO-UNDO. 
  METHOD PUBLIC VOID DoWait( ). 
    /* Display and wait for the non-modal form to close */ 
    WAIT-FOR Application:Run( INPUT THIS-OBJECT ). 
  END METHOD. 
  CONSTRUCTOR PUBLIC r-WaitForms( ): 
    /* Initialize and subscribe to events */ 
    InitializeComponent( ). 
    THIS-OBJECT:FormClosing:Subscribe(Form_Closing). 
  END CONSTRUCTOR. 
  METHOD PRIVATE VOID InitializeComponent( ): 
    /* Initialize the non-modal form class and components */ 
    rFormDescr = NEW Label( ). 
    /* Initialize the form description label */ 
    rFormDescr:Text     = "Click the Close (X) button of this form to pop-up 
a dialog box ...". 
    rFormDescr:Size     = NEW System.Drawing.Size( INPUT 330, INPUT 13 ). 
    rFormDescr:Location = NEW System.Drawing.Point( INPUT 4, INPUT 6 ). 
    /* Initialize the non-modal form */ 
    THIS-OBJECT:FormBorderStyle = FormBorderStyle:FixedSingle. 
    THIS-OBJECT:Text = "This is my form.". 
    THIS-OBJECT:Controls:Add( INPUT rFormDescr ). 
    THIS-OBJECT:Size = NEW System.Drawing.Size( INPUT rFormDescr:Width, INPUT 
60 ). 
  END METHOD. 
  METHOD PRIVATE VOID Form_Closing 
    ( INPUT sender AS System.Object, INPUT e AS FormClosingEventArgs ): 
    DEFINE VARIABLE rDialog       AS CLASS Progress.Windows.Form NO-UNDO. 
    DEFINE VARIABLE rDialogDescr  AS CLASS Label NO-UNDO. 
    DEFINE VARIABLE rOKButton     AS CLASS Button NO-UNDO. 
    DEFINE VARIABLE rCancelButton AS CLASS Button NO-UNDO. 
    DEFINE VARIABLE enDialogResult AS CLASS DialogResult NO-UNDO. 
    /* Create dialog box components */ 
    ASSIGN 
      rDialog       = NEW Progress.Windows.Form( ) 
      rDialogDescr  = NEW Label( ) 
      rOKButton     = NEW Button( ) 
      rCancelButton = NEW Button( ). 
    /* Initialize the dialog description label */ 
    rDialogDescr:Text     = "Click OK to close form or click Cancel to leave 
form open.". 
    rDialogDescr:Size     = NEW System.Drawing.Size( INPUT 306, INPUT 13). 
    rDialogDescr:Location = NEW System.Drawing.Point( INPUT 4, INPUT 6 ). 
    /* Initialize the buttons */ 
    rOKButton:Text = "OK". 
    rOKButton:Size = NEW System.Drawing.Size( INPUT 60, INPUT 20). 
    rOKButton:Location = NEW System.Drawing.Point 
      ( INPUT INTEGER( ( rDialogDescr:Width - 124 ) / 2 ),  
        INPUT rDialogDescr:Top + rDialogDescr:Height + 8 ). 
    rOKButton:DialogResult = DialogResult:OK. 
    rCancelButton:Text = "Cancel". 
    rCancelButton:Size = NEW System.Drawing.Size( INPUT 60, INPUT 20 ).  
    rCancelButton:Location = NEW System.Drawing.Point 
      ( INPUT rOKButton:Left + rOKButton:Width + 4,  
        INPUT rDialogDescr:Top + rDialogDescr:Height + 8 ). 
    rCancelButton:DialogResult = DialogResult:Cancel. 
    /* Initialize the modal dialog box with label and buttons */ 
    rDialog:FormBorderStyle = FormBorderStyle:FixedDialog. 
    rDialog:Controls:Add( INPUT rDialogDescr ). 
    rDialog:Controls:Add( INPUT rOKButton ). 
    rDialog:Controls:Add( INPUT rCancelButton ). 
    rDialog:Text = "My form is closing ...". 
    rDialog:Size = NEW System.Drawing.Size( INPUT 306, INPUT 106 ). 
    /* Display dialog box to handle FormClosing event and the results */ 
    WAIT-FOR rDialog:ShowDialog( ) SET enDialogResult. 
    IF EnumHelper:AreEqual 
      ( INPUT enDialogResult, INPUT DialogResult:Cancel ) THEN DO: 
      MessageBox:Show( INPUT "My form closing was canceled." ). 
      e:Cancel = TRUE. /* Cancel FormClosing; leave the main form open */ 
    END. 
    ELSE DO: 
      MessageBox:Show( INPUT "My form is closing OK." ). 
      e:Cancel = FALSE. /* Continue FormClosing; close the main form */ 
    END. 
    rDialog:Dispose( ). /* Dispose modal form object */  
  END METHOD. /* Form_Closing */ 
END CLASS. 

The Form_Closing( ) method passes INPUT parameters from .NET for the FormClosing event. One of these parameters (e) is a System.Windows.Forms.FormClosingEventArgs object, which contains a Cancel property whose setting allows the event handler to either complete the FormClosing event or interrupt and cancel the FormClosing event. To determine how to set this property, the event handler instantiates, initializes, and displays another Progress.Windows.Form class (rDialog) as a modal dialog box.

The dialog box contains two buttons, rOKButton and rCancelButton, whose DialogResult properties are set to the System.Windows.Forms.DialogResult enumeration values OK and Cancel, respectively. The event handler displays rDialog as a modal form by executing the WAIT-FOR statement, which calls the modal input-blocking method System.Windows.Forms.Form:ShowDialog( ). (For more information on this method, see the notes.)

When you click one of the two dialog buttons, this causes the dialog box to close and the ShowDialog( ) method to return. This automatically sets the DialogResult property on rDialog to the value of the DialogResult property on the button that you have clicked and also returns the same property value as the value of ShowDialog( ), which the WAIT-FOR statement assigns to the variable, enDialogResult. The event handler then uses the static AreEqual( ) method on the Progress.Util.EnumHelper class to test the value of enDialogResult and set the e:Cancel property to either complete the FormClosing event or cancel the FormClosing event and leave the non-modal form open for further input. The Dispose( ) method call at the end of the event handler is required to allow the modal form object to be garbage collected (see the notes).

Note: The calls to System.Windows.Forms.MessageBox:Show( ) display a message box similar to the ABL MESSAGE statement with the VIEW-AS ALERT-BOX option.

To instantiate r-WaitForms and display the non-modal form, you can thus run a procedure with code like this:

DEFINE VARIABLE rWaitForms AS CLASS r-WaitForms NO-UNDO. 
rWaitForms = NEW r-WaitForms( ). 
rWaitForms:DoWait( ). 

Notes
See also

Type-name syntax, USING statement, WAIT-FOR statement (ABL only)


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex