Example: dispcust.4gl (MAIN block)

Your form can display options to the user using action views - buttons, dropdown menus (aka topmenus), toolbars, and other items on the window.

This portion of the dispcust.4gl program connects to a database, opens a window, and displays a form and a menu.

Program dispcust.4gl:
  1 -- dispcust.4gl
  2 
  3 SCHEMA custdemo
  4 
  5 MAIN
  6 
  7   CONNECT TO "custdemo"
  8 
  9   CLOSE WINDOW SCREEN
 10   OPEN WINDOW w1 WITH FORM "dispcust"
 11      ATTRIBUTES(TEXT="Customer")
 12 
 13   MENU "Customer"
 14     ON ACTION query
 15       CALL query_cust()
 16     ON ACTION exit
 17       EXIT MENU
 18   END MENU
 19 
 20   CLOSE WINDOW w1
 21 
 22   DISCONNECT CURRENT
 23 
 24 END MAIN
Note:
  • Line 1: This is a comment line.
  • Line 3: The SCHEMA statement is required since variables are defined as LIKE a database table in the function query_cust.
  • Line 7 opens the connection to the custdemo database.
  • Line 9 closes the default window named SCREEN, which is opened each time the runtime system starts a program containing interactive statements
  • Line 10 uses the WITH FORM syntax to open a window having the identifier w1 containing the form identified as dispcust. The window name must be unique among all windows defined in the program. Its scope is the entire program. You can use the window's name to reference any open window in other modules with other statements. Although there can be multiple open windows, only one window may be current at a given time. By default, the window that opens will be a normal application window. The form identifier is the name of the compiled .42f file (dispcust.42f). The form identifier must be unique among form names in the program. Its scope of reference is the entire program. The OPEN WINDOW uses an ATTRIBUTES clause to specify the window title with the TEXT attribute.
  • Lines 13 through 18 contain the interactive MENU statement. By default, the menu options query and exit are displayed as buttons in the window, with Customer as the menu title. When the MENU statement is executed, the buttons are enabled, and control is turned over to the user. If the user selects the query button, the function query_cust will be executed. Following execution of the function, the action views (buttons in this case) are re-enabled and the program waits for the user to select an action again. If the user selects the exit button, the MENU statement is terminated, and the program continues with the instruction following the MENU block.
  • Line 20: The window w1 is closed which automatically closes the form, removing the form and the window objects from the user interface.
  • Line 22: The program disconnects from the database; as there are no more statements in MAIN, the program terminates.