Top
PowerCOBOL V11.0 Reference
FUJITSU Software

5.100 ThruEvents Method

Description:

Compels window messages, which are waiting for an event procedure to finish, to execute before the event procedure finishes.

For example, if you code an event procedure "A" that takes a long time to execute, and use a Timer control to update the form in the Timer event, the Timer event will wait for the procedure "A" to conclude.

If you invoke the ThruEvents method at intervals from the procedure "A", the Timer events work smoothly.

Refer to the ThruEvents Example for details.

Caution: The ThruEvents method can cause unexpected results because of timing or procedure coding errors. Refer to Unexpected Results when using the ThruEvents Method for more details.

Use this method with care.

Used in controls:

None.

Used in objects:

Form

Parameters:

None.

Return value:

None.

Example:

See the ThruEvents Example

Backward compatibility
method name:

None.

Example of the ThruEvents Method

The code below demonstrates code containing a loop that invokes the ThruEvents method every 1000th iteration. This enables the counter to be displayed (every 1000th iteration) and for the event to exit when the cancel button is clicked.

WORKING-STORAGE SECTION of the Form
01 RUNNING-FLAG PIC S9(4) GLOBAL VALUE 0.
  88 IS-RUNNING  VALUE 1.

If the click event is executing, exit program to prevent(restrict) the event nesting

Click event of a CommandButton, which invokes the ThruEvents Method
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC S9(9) COMP-5.
PROCEDURE DIVISION.
    IF IS-RUNNING THEN
      EXIT PROGRAM                 *> Exit to prevent nesting of the event
    END-IF
    MOVE 1 TO RUNNING-FLAG.           *> Sets the executing flag
    PERFORM VARYING I FROM 1 BY 1 UNTIL I > 1000000
      MOVE I TO "Caption" OF COUNTER	*> Display counter
      IF FUNCTION MOD (I 1000) = 0 THEN
        INVOKE POW-SELF "ThruEvents"  *> Executes any waiting event procedures
        IF NOT IS-RUNNING THEN        *> Exits if the cancel button is clicked
          EXIT PERFORM
        END-IF
      END-IF
    END-PERFORM
    MOVE 0 TO RUNNING-FLAG.           *> Releases the executing flag
Click event of the Cancel CommandButton
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
    MOVE 0 TO RUNNING-FLAG.		*> Sets the executing flag to 0
QueryClose event of the Form
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01  POW-CANCEL  PIC S9(4) COMP-5.
PROCEDURE DIVISION USING POW-CANCEL.
    IF IS-RUNNING THEN
      MOVE POW-TRUE TO POW-CANCEL
    END-IF