Progress
Programming
Handbook
Program Structure in an Event-driven Program
An event-driven program is a collection of triggered responses. The basic structure is as follows.
- Definitions — Define and enable the user interface objects that comprise its interface.
- Triggers — Define the behavior that should occur in response to events applied to these user interface objects. The code within a trigger block tells the system to watch for a condition, execute a block of code, and control the return.
- Main Logic — Establish a WAIT-FOR state to allow the user to interact with the user interface objects and then dismiss the user interface when the WAIT-FOR condition is satisfied. The WAIT-FOR statement typically tests for the end condition.
The following example is a simple event-driven program using the WAIT-FOR statement:
These notes help explain the code:
- The two DEFINE BUTTON statements define two static buttons, btn_1 and btn_2, and label them “Next” and “Prev”. These labels provide visual cues to the user that relate to each button’s function.
- The next two statements instruct Progress to find the first customer record in the database and display the Cust-Num, Name, and Phone data in frame f, labeling each field to the left and center.
NOTE: At run time, the CHOOSE event in this example is applied by clicking btn_1. Other programming techniques for applying a CHOOSE event include using a 4GL statement or a keyboard accelerator.- The first ON statement defines trigger code that Progress executes each time the user applies a CHOOSE event to btn_1, the Next button. This CHOOSE behavior applies only to btn_1.
The trigger code instructs Progress to find the next customer record and omit any error messages. In the next line, Progress tests whether a customer record was found. If not, Progress finds the last customer record and the terminal beeps. Finally, Progress displays the contents of the Cust-Num, Name, and Phone fields in frame f and ends processing in the block.
- The next ON statement defines trigger code that Progress executes each time the user applies a CHOOSE event to btn_2, the Prev button. This CHOOSE behavior applies only to btn_2.
The trigger code instructs Progress to find the previous customer record and omit any error messages. In the next line, Progress tests whether a customer record was found. If not, Progress finds the first customer record and the terminal beeps. Finally, Progress displays the contents of the Cust-Num, Name, and Phone fields in frame f and ends processing in the block.
- The last ON statement defines trigger code that Progress executes each time the user applies a LEAVE event in the Phone field. This LEAVE behavior applies only to the Phone field.
The trigger code instructs Progress to compare the current value in the Phone field to its value in the database. If the two values are not the same, Progress moves the new Phone data into the database, the terminal beeps, an information box appears and displays the message “Phone Number changed”, and processing ends in this block.
- The ENABLE statement places the Phone field on the screen with the Prev and Next buttons in frame f. (When Progress executes this statement, frame f is viewed on the screen.)
- The WAIT-FOR statement establishes a WAIT-FOR condition for frame f. When the user applies a GO event, the WAIT-FOR condition is satisfied.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |