Ending dynamic dialogs

Describes how to terminate dynamic dialogs.

Implementing the accept and cancel actions

Regular static dialog instructions implement the accept and cancel actions, to respectively validate or abort the dialog.

These actions are created automatically for static dialogs, but must be created by hand for dynamic dialogs.

In the case of cancel, you can mimic the behavior of static dialogs by setting the INT_FLAG register to TRUE and then leave the WHILE loop with an EXIT WHILE.

For the accept action, call the ui.Dialog.accept() method to validate field input and leave the dialog, and execute an EXIT WHILE in the "AFTER INPUT" event to leave the dialog loop.

For example, to implement the accept and cancel actions for a simple record input:
DEFINE d ui.Dialog,
       t STRING
...
LET d = ui.Dialog.createInputByName(fields)
CALL d.addTrigger("ON ACTION cancel")
CALL d.addTrigger("ON ACTION accept")
...
WHILE (t := d.nextEvent()) IS NOT NULL
    CASE t
    WHEN "ON ACTION cancel"
      LET int_flag = TRUE
      EXIT WHILE
    WHEN "ON ACTION accept"
      CALL d.accept()
    WHEN "AFTER INPUT"
      EXIT WHILE
  END CASE
END WHILE

Terminating the dialog

Some synchronization code needs to be implemented to properly destroy the dynamic dialog.

A dialog needs to be destroyed before closing its corresponding window/form.

In order to terminate a dialog, call the close() dialog method and assign NULL to the ui.Dialog variable referencing the dialog object. This will close the dialog and destroy the corresponding object, if no other variables references it.

When the dialog object is terminated, the corresponding window can also be closed:
...
  WHEN "ON ACTION cancel"
    EXIT WHILE
END WHILE
CALL d.close()
LET d = NULL
CLOSE WINDOW w1