Progress
Programming
Handbook


Programming Example

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

p–nedrvr.p
/* p-nedrvr.p  */ 
DEFINE VARIABLE hPub  AS HANDLE. 
DEFINE VARIABLE hSub1 AS HANDLE. 
DEFINE VARIABLE hSub2 AS HANDLE. 
DEFINE BUTTON bNewCust LABEL "New Customer". 
DEFINE BUTTON bQuit LABEL "Quit". 
RUN p-nepub.p PERSISTENT set hPub. 
RUN p-nesub1.p PERSISTENT set hSub1 (hPub). 
RUN p-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, p-nepub.p, publishes the event NewCustomer:

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

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

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

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

p–nesub2.p
/* p-nesub2.p */ 
PROCEDURE NewCustomer: 
  DEFINE INPUT PARAMETER name AS CHAR. 
  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, p-nedrvr.p.


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