PreviousNextIndex

PUBLISH statement

Causes an ABL named event to occur.

Note: ABL named events are completely different from the key function, mouse, widget, and direct manipulation events described in the "Handle-based Object Events Reference" section. They are also different from the class events described in the "Class Events Reference" section.
Syntax

PUBLISH event-name 
  [ FROM publisher-handle ] 
  [ ( parameter [ , parameter ] ... ) ]  

event-name
FROM publisher-handle
( parameter [ , parameter ] ... )
Example

The following example consists of four procedure files: a driver, a publisher, and two subscribers. The driver, r-nedrvr.p, runs the publisher and the two subscribers persistently, then subscribes to the event NewCustomer on behalf of the second subscriber.

r-nedrivr.p
/* r-nedrvr.p  */ 
DEFINE VARIABLE hPub  AS HANDLE NO-UNDO. 
DEFINE VARIABLE hSub1 AS HANDLE NO-UNDO. 
DEFINE VARIABLE hSub2 AS HANDLE NO-UNDO. 
DEFINE BUTTON bNewCust LABEL "New Customer". 
DEFINE BUTTON bQuit    LABEL "Quit". 
RUN r-nepub.p  PERSISTENT SET hPub. 
RUN r-nesub1.p PERSISTENT SET hSub1 (hPub). 
RUN r-nesub2.p PERSISTENT SET hSub2. 
/* Subscribe to event NewCustomer on behalf of subscriber 2 */ 
SUBSCRIBE PROCEDURE hSub2 TO "NewCustomer" IN hPub. 
FORM bNewCust bQuit WITH FRAME x. 
ENABLE ALL WITH FRAME x. 
ON CHOOSE OF bNewCust RUN NewCust in hPub. 
WAIT-FOR CHOOSE OF bQuit OR WINDOW-CLOSE OF CURRENT-WINDOW. 

The publisher, r-nepub.p, publishes the event NewCustomer:

r-nepub.p
/* r-nepub.p */ 
PROCEDURE NewCust: 
  DEFINE VARIABLE name AS CHARACTER NO-UNDO INITIAL "Sam". 
  /* Let subscriber know new customer */ 
  PUBLISH "NewCustomer" (INPUT name). 
END PROCEDURE. 

The first subscriber, nesub1.p, subscribes to the event NewCustomer:

r-nesub1.p
/* r-nesub1.p */ 
DEFINE INPUT PARAMETER hPub AS HANDLE NO-UNDO. 
SUBSCRIBE TO "NewCustomer" IN hPub. 
PROCEDURE NewCustomer: 
  DEFINE INPUT PARAMETER name AS CHARACTER NO-UNDO. 
  MESSAGE "Subscriber 1 received event NewCustomer concerning" name 
    VIEW-AS ALERT-BOX. 
END. 

The second subscriber, nesub2.p, already subscribed to the event NewCustomer, cancels all subscriptions:

r-nesub2.p
/* r-nesub2.p */ 
PROCEDURE NewCustomer: 
  DEFINE INPUT PARAMETER name AS CHARACTER NO-UNDO. 
  MESSAGE "Subscriber 2 received event NewCustomer concerning" name 
    VIEW-AS ALERT-BOX. 
  /* This subscriber receives the first event, then removes itself */ 
  UNSUBSCRIBE TO ALL. 
END. 

To start the example, run the driver, r-nedrvr.p.

Notes
See also

Publish( ) event method, PUBLISHED-EVENTS attribute, SUBSCRIBE statement, UNSUBSCRIBE statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex