Progress
External Program
Interfaces


Event-driven Exchanges

In an event-driven exchange, the DDE server application sends the value of the data item to the client whenever the value of the data item changes. Each server data item you set up for event-driven exchange actually participates in a series of exchanges, totally dependent on how often the data item changes. If the data item never changes value, no exchange occurs.

Steps To Setting Up Event-driven Exchanges—Advise Links

To set up and manage event-driven exchanges for a data item, your application must complete these steps:

  1. Specify the server data item in a DDE ADVISE statement, using the START option. This creates an advise link to the data item from Progress. From this point in the procedure, the DDE server monitors the specified data item, notifying Progress whenever its value changes.
  2. Add an ON DDE-NOTIFY OF FRAME DDEframe statement, where DDEframe is the name of the frame that owns the conversation. In the trigger block for the statement, invoke the DDE GET statement to retrieve the new value of the data item (just like a DDE REQUEST) and process it as you want. Progress triggers this DDE-NOTIFY event and posts it to the appropriate DDE frame when notified of the value change. The Progress client application then executes the event trigger when it blocks for I/O or invokes the PROCESS EVENTS statement. If you have more than one advise link established for the conversation, you can determine what data item changed by checking the value of the DDE-ITEM attribute of the DDE frame.
  3. NOTE: In general, do not block for I/O (for example, invoke an UPDATE statement) or invoke a PROCESS EVENTS statement within the trigger for a DDE-NOTIFY event. This can cause Progress to update the DDE frame attributes for a new DDE-NOTIFY event before you have completed the processing for a prior event.

  4. At any point in the procedure, if you want to stop event-driven exchanges for the data item, specify the data item in a DDE ADVISE statement using the STOP option. This removes the advise link and directs the server to cease monitoring value changes in the data item. This does not terminate the conversation in any way and you can continue to access the data item with other exchanges or create another advise link to the data item.
Coordinating DDE Client/Server Communications

If you use event-driven exchanges, you might also want to set a value for the MULTITASKING-INTERVAL attribute of the SESSION system handle. The value of this attribute determines how often Progress checks for application events. An appropriate value can help your client application interact more smoothly with its DDE server. For more information, see the Progress Language Reference .

Applications For Event-Driven Exchanges

You might use event-driven exchanges to tie data item values in a Progress application to those in a spreadsheet, calender scheduler, or some other database application that might be running in your application environment. For example, the following code fragment retrieves the latest value of the cell at row 4, column 2 (the “B” column) in an Excel worksheet and stores it in a Progress editor field:

DEFINE VARIABLE sheet AS INTEGER.
DEFINE VARIABLE sty AS CHARACTER.
DEFINE VARIABLE ed AS CHARACTER 
  VIEW-AS EDITOR SIZE 20 by 2.

ON DDE-NOTIFY OF FRAME MainFrame 
DO:   
  DDE GET sheet TARGET sty ITEM "r4c2".
  sty = SUBSTR(sty, 1, 20).           /* Drop the CR/LF */
  ed:VALUE = IN FRAME MainFrame = sty.
END.
              .
              .
              .
DDE ADVISE sheet START ITEM "r4c2".
              .
              .
              . 

Multiple Conversations With Advise Links

If a DDE frame owns more than one conversation with advise links, you can get the channel number of the conversation and the name of the data item to which a DDE-NOTIFY event applies from the DDE-ID and DDE-ITEM attributes of the frame. This is enough information to retrieve the value that triggered the event with the DDE GET statement. However, you might also need the application and topic names to fully identify the item from which you are retrieving data. This is necessary if the different conversations (different topics and/or applications) include links to data items with the same name. You can obtain the application and topic names related to the current DDE-NOTIFY event from the DDE-NAME and DDE-TOPIC attributes of the frame. For more information on DDE frame attributes, see the "Defining Conversation Endpoints—DDE Frames" section.

However, you might find it simpler to manage event-driven exchanges by using a separate DDE frame for each advise link. In this case, you initiate an additional conversation for each advise link that you want to establish for the same application and topic, using a separate DDE frame for each conversation. You then set up each advise link using its own conversation ID. When a DDE-NOTIFY event occurs for a linked data item, you do not have to check for the source of the event, because each data item has its own frame trigger. The following code fragment shows the essential elements of this technique to link two data cells in the same Excel worksheet to two Progress variables (quote1 and quote2):

DEFINE VARIABLE link1 AS INTEGER.
DEFINE VARIABLE link2 AS INTEGER.
DEFINE VARIABLE quote1 AS CHARACTER.
DEFINE VARIABLE quote2 AS CHARACTER.
DEFINE FRAME Flink1.
DEFINE FRAME Flink2.

ON DDE-NOTIFY OF FRAME Flink1 DO:
    DDE GET link1 TARGET quote1 ITEM "R2C1".
              .
              .
              .
ON DDE-NOTIFY OF FRAME Flink2 DO:
    DDE GET link2 TARGET quote2 ITEM "R2C2".
              .
              .
              .
DDE INITIATE link1 FRAME Flink1:HANDLE 
    APPLICATION "EXCEL" TOPIC "Sheet1".
DDE INITIATE link2 FRAME Flink2:HANDLE 
    APPLICATION "EXCEL" TOPIC "Sheet1".

DDE ADVISE link1 START ITEM "R2C1".
DDE ADVISE link2 START ITEM "R2C2". 


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