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.

  1. Definitions — Define and enable the user interface objects that comprise its interface.
  2. 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.
  3. 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:

p-eventd.p 
DEFINE BUTTON btn_1 LABEL "Next". 
DEFINE BUTTON btn_2 LABEL "Prev". 
FIND FIRST customer. 
DISPLAY cust-num name phone SKIP (0.5) 
      btn_2 TO 40 SPACE btn_1 
      SKIP (0.5) 
    WITH FRAME f SIDE-LABELS. 
ON CHOOSE OF btn_1 DO: 
  FIND NEXT customer NO-ERROR. 
  IF NOT AVAILABLE customer THEN DO: 
      FIND LAST customer. 
      BELL. 
  END. 
  DISPLAY cust-num name phone WITH FRAME f. 
END. 
ON CHOOSE OF btn_2 DO: 
  FIND PREV customer NO-ERROR. 
  IF NOT AVAILABLE customer THEN DO: 
      FIND FIRST customer. 
      BELL. 
  END. 
  DISPLAY cust-num name phone WITH FRAME f. 
END. 
ON LEAVE OF phone DO: 
  IF INPUT customer.phone NE customer.phone THEN DO: 
    ASSIGN customer.phone. 
    BELL. 
    MESSAGE "Phone Number changed." 
      VIEW-AS ALERT-BOX INFORMATION. 
  END. 
END. 
ENABLE phone btn_2 btn_1 WITH FRAME f. 
WAIT-FOR GO OF FRAME f. 

These notes help explain the code:


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095