Progress
Language Tutorial
for Character


Responding to Events

For every widget, there is always a default response for each possible event. The default response for pressing TAB with most widgets is to move input focus to the next enabled widget. The default response for pressing a character key when a fill-in field has focus is to display that character in the field.

The default response for many events is no response. As mentioned earlier, some keystrokes with certain widgets don’t make sense. Therefore, Progress ignores these events. Remember that for every widget-event pair, Progress executes the default response, even though that response may be no response.

Now you need a way to program new responses for widget-event pairs. For example, in the “Hello Progress World!” application, suppose you want to display a message as soon as input focus moves to Field3. The Progress programming structure for this task consists of an ON statement and a block of code called a trigger. The ON statement is the device that establishes the condition that executes a trigger. A trigger is the code that Progress executes only when a specified widget receives a specified event. A trigger is a programmed response. A programmed response occurs before the default response.

Using Triggers

Follow these steps to create a trigger:

  1. Open lt-03-02.p.
  2. Choose Compile Run.
  3. Click Field3. Notice the message that now appears at the bottom of the window:
  4. Press RETURN to end the procedure.
  5. Press SPACEBAR to return to the Procedure Editor.

The following code points out the new language element:

lt-03-02.p
DEFINE VARIABLE Field1 AS CHARACTER INITIAL "Hello".
DEFINE VARIABLE Field2 AS CHARACTER INITIAL "Progress".
DEFINE VARIABLE Field3 AS CHARACTER INITIAL "World!". 
DISPLAY SKIP(3) Field1 SKIP(2) Field2 SKIP(2) Field3 
  WITH SIDE-LABELS CENTERED NO-BOX.
  
ENABLE Field1 Field2 Field3. 

/* TRIGGER */
ON ENTRY OF Field3
DO:
  MESSAGE "Press Return in Field3 to exit the procedure.".
END.
 
WAIT-FOR RETURN OF Field3. 

Notice the new language element in the example, the ON statement. The ON statement sets up the trigger. In the example, ENTRY is the event and Field3 is the widget. (ENTRY is an event that occurs when the user or the application gives input focus to a widget.) The MESSAGE statement is the trigger that occurs when Field3 receives the ENTRY event.

NOTE: By default, window widgets reserve space at the bottom of the window to display messages from Progress and your application. The MESSAGE statement automatically outputs text enclosed in quotes to the message area.

This is a partial syntax for the ON statement. (For complete syntax descriptions, see the Progress Language Reference or access the On-line Language Reference module of the help system.)

SYNTAX
ON event-list  OF widget-list
  [ OR event-list OF widget-list ] ...
    trigger-block 

The following table describes the elements of the ON statement:

Components
Description
event-list 
A single event or a comma-separated list of events. One of the widgets specified must receive one of the events listed for the code in the trigger block to execute.
widget-list 
A single widget or a comma-separated list of widgets. One of the widgets specified must receive one of the events listed for the code in the trigger block to execute.
OR 
Use the OR phrase to create another widget-event pair that can execute the code in the trigger block.
trigger-block 
A single 4GL statement or a block of statements that Progress executes when a specified widget receives a specified event. If the trigger block contains only one statement, then you don’t have to enclose the statement in the DO. . .END syntax. For example:

ON event OF widget
MESSAGE "No DO syntax needed.".

Defining triggers is part of the basic Progress code template. Adding triggers to the basic template gives you this new coding template:

  1. Define widgets.
  2. Display widgets.
  3. Enable widgets.
  4. Define triggers.
  5. Block execution.

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