Example: comutils.4gl

The comutils.4gl module implements a set of utility functions used by other modules.

The mbox_yn function

The MENU statement has an optional STYLE attribute that can be set to "dialog", automatically opening a temporary popup window. You can define a message and icon with the COMMENT and IMAGE attributes. This provides a simple way to prompt the user to confirm some action or operation that has been selected.

Figure: A MENU with STYLE="dialog"

This figure is a screenshot of a dialog menu used to prompt the user for validation when deleting a row.
The mbox_yn function shows a popup dialog window asking the user for a yes or no answer, and returns TRUE if the user accepts:
  1 PUBLIC FUNCTION mbox_yn(qt STRING, msg STRING) RETURNS BOOLEAN
  2   DEFINE r BOOLEAN
  3   MENU qt ATTRIBUTE (STYLE="dialog",COMMENT=msg)
  4     COMMAND "Yes"
  5       LET r = TRUE
  6       EXIT MENU
  7     COMMAND "No"
  8       LET r = FALSE
  9       EXIT MENU
 10   END MENU 
 11   RETURN r 
 12 END FUNCTION
Note:
  • Line 1 defines the function with a parameter for the popup window title and the question/message to be displayed in the window. The return value is a boolean.
  • Line 2 defines a local function variable to hold the answer of the user.
  • Line 3 thru 10 implements the MENU dialog with STYLE="dialog".
  • Lines 11 returns the boolean value, set from the user choice.

The mbox_ok function

The mbox_ok function shows a popup window with a message, and OK button:
  1 PUBLIC FUNCTION mbox_ok(qt STRING, msg STRING) RETURNS ()
  2   MENU qt ATTRIBUTE (STYLE="dialog",COMMENT=msg)
  3     COMMAND "OK"
  4       EXIT MENU
  5   END MENU
  6 END FUNCTION
Note:
  • Line 1 defines the function with a parameter for the popup window title and the message to be displayed in the window. No value is returned.
  • Line 2 thru 5 implements the MENU dialog with STYLE="dialog".