PreviousNextIndex

ON statement

The ON statement specifies a trigger for one or more events or redefines terminal keys for an application.

Syntax

ON event-list 
  {     ANYWHERE 
     |  { OF widget-list 
            [ OR event-list OF widget-list ] ... 
            [ ANYWHERE ] 
        } 
  } 
  {     trigger-block 
     |  REVERT 
     |  { PERSISTENT RUN procedure 
            [ ( input-parameters ) ] 
        } 
  } 

ON event OF database-object  
  [ referencing-phrase ] 
  [ OVERRIDE ] 
  { trigger-block | REVERT } 

ON key-label key-function 

ON "WEB-NOTIFY" ANYWHERE  { trigger-block } 

event-list
widget-list
ANYWHERE
event
database-object [ referencing-phrase ]
OVERRIDE
trigger-block
REVERT
PERSISTENT RUN procedure [ ( input-parameters ) ]
key-label
key-function
Examples

The following example defines a WRITE trigger for the customer table:

r-oncst.p
ON WRITE OF Customer NEW new-cust OLD old-cust DO: 
  IF new-cust.City <> old-cust.City AND 
    new-cust.PostalCode = old-cust.PostalCode THEN DO: 
    MESSAGE "Must update postal code, too.". 
    RETURN ERROR. 
  END. 
END. 
FOR EACH Customer: 
  UPDATE Customer. 
END. 

The trigger compares the Customer record before the write with the Customer record after the write. If the city has changed and the postal code has not changed, the trigger displays a message and cancels the write operation.

The following example uses the ON statement to set up a trigger for two buttons:

r-widget.p
DEFINE BUTTON b_next LABEL "Next". 
DEFINE BUTTON b_prev LABEL "Previous". 
DEFINE BUTTON b_quit LABEL "Quit". 
DEFINE FRAME butt-frame 
  b_next b_prev 
  WITH CENTERED ROW SCREEN-LINES - 1. 
DEFINE FRAME info 
  Customer.CustNum Customer.Name 
  b_quit AT ROW-OF Customer.CustNum + 2 COLUMN-OF Customer.CustNum + 18 
  WITH CENTERED TITLE "Customers"  ROW 2 1 COL. 
ON CHOOSE OF b_next, b_prev DO: 
  IF SELF:LABEL = "Next" THEN 
    FIND NEXT Customer NO-LOCK. 
  ELSE  
    FIND PREV Customer NO-LOCK. 
  DISPLAY Customer.CustNum Customer.Name WITH FRAME info. 
END. 
   
ENABLE b_next b_prev WITH FRAME butt-frame. 
ENABLE b_quit WITH FRAME info. 
WAIT-FOR END-ERROR OF FRAME butt-frame OR 
  CHOOSE OF b_quit IN FRAME info FOCUS b_next IN FRAME butt-frame. 

The following procedure sets up mappings for GO, HELP, and END and defines CTRL+X to ring the terminal bell:

r-onstmt.p
ON F1 GO.       /* F1 will now perform the GO function */ 
ON F2 HELP.     /* F2 will now perform the HELP function   */ 
ON CTRL-X BELL. /* The Ctrl-X key will be disabled */ 
ON F5 ENDKEY.   /* F5 will always raise the ENDKEY condition; never ERROR*/ 

Notes
See also

APPLY statement, Widget phrase


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex