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
: TheSCHEMA
statement is required since variables are defined asLIKE
a database table in the functionquery_cust
. - Line
7
opens the connection to thecustdemo
database. - Line
9
closes the default window namedSCREEN
, which is opened each time the runtime system starts a program containing interactive statements - Line
10
uses theWITH FORM
syntax to open a window having the identifierw1
containing the form identified asdispcust
. 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. TheOPEN WINDOW
uses anATTRIBUTES
clause to specify the window title with theTEXT
attribute. - Lines
13
through18
contain the interactiveMENU
statement. By default, the menu options query and exit are displayed as buttons in the window, withCustomer
as the menu title. When theMENU
statement is executed, the buttons are enabled, and control is turned over to the user. If the user selects the query button, the functionquery_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, theMENU
statement is terminated, and the program continues with the instruction following theMENU
block. - Line
20
: The windoww1
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 inMAIN
, the program terminates.