11. Managing Event Queues : Event-based Programming : How You Can Interrupt an Event Block
 
Share this page                  
How You Can Interrupt an Event Block
Typically, OpenROAD finishes executing the current event block before moving on to the next event in the queue. However, you can use the resume statement to interrupt the current event block. Statements following the resume statement are not executed.
In the following sample frame script, the resume statement is used to interrupt the event block if the user decides to not delete the videos. Otherwise, the processing continues.
on cleartable checkout_form.checkout =

begin
    status = CurFrame.ConfirmPopup(messagetext =
    'You are going to delete all checked out videos' +
    ' for this customer.');
if status != PU_OK then
    resume;
endif;
/* We will delete the rows in reverse order to play it
** safe */
i = checkout_form.checkout.LastRow;
while i > 0 do
    /* This does not actually delete the row, but tags
    ** it with a rowstate of RS_DELETED. */
    checkout_form.checkout.SetRowDeleted
        (rownumber = i);
    i = i - 1;
endwhile;

field(checkout_form.checkout).HasDataChanged = TRUE;
end
Because the resume statement terminates the current operation, it is usually the last statement either in the event block or in the statement list of the if statement (as shown in the previous example).
The resume statement is useful for ensuring data validation. When you use the SetValue event to perform data validation for a field, the resume statement can prevent the user from leaving the field when the data is invalid. The user remains on the field that triggered the SetValue event, unless you use the resume next statement to continue with the next operation or use the CurFrame.InputFocusField attribute to move the user to a specified field.
For more information about resume next and about the InputFocusField attribute, see the Language Reference Guide.
When the resume statement is executed in an event block for an event that is part of an event chain, OpenROAD removes the remaining events in the chain from the event queue. For example, after a user triggers a SetValue event for a field and leaves the field, an Exit event is triggered for that field, and an Entry event is triggered for the next field getting the input focus.
However, you can use the resume statement in the SetValue event block to prevent the user from entering invalid data. When the SetValue event block executes the resume statement, the Exit and Entry events are removed from the queue and the user remains in the field with invalid data.
Because the resume statement removes remaining events from an event chain, you can use it to prevent a window from closing when the user selects the window manager close operation for the running frame. When the user closes a window, OpenROAD triggers both the WindowClose and Terminate events for the frame.
To keep the window open under specified circumstances, you can put a resume statement in a WindowClose event block. This statement removes the Terminate event from the event queue and prevents the window from closing.
You cannot use a resume statement in a Terminate event to prevent the window from closing. Regardless of how a Terminate event block completes, it always terminates the frame and the window. For this reason, OpenROAD always processes a WindowClose event, if specified, before a Terminate event block.