Progress
ADM 2 Guide


Defining Dynamic SmartLinks

Sometimes a SmartObject application requires a link that passes messages between SmartObjects more dynamically; that is, the particular message to be passed (and any resulting processing) is determined by an application user’s run-time choice. This type of link is a dynamic SmartLink.

When you define a dynamic SmartLink, you do not need to provide the support structure for standard events required for static SmartLinks (see the previous section for details). If, at design time, you define between two SmartObjects a SmartLink that is not in the SupportedLinks list for either object, the addLink procedure registers the link as a subscription to an event of the same name as the links. (You can also do this programmatically, by running the addLink procedure in application code.)

The following example illustrates how to define a dynamic SmartLink. This SmartLink, called ProcessCalc, links a simple SmartObject and a SmartDataObject, passing messages that invoke processing in the SmartDataObject. The particular message sent, and the processing invoked, are determined at run time by the choice of the application user.

Follow these steps in the AppBuilder to define the ProcessCalc dynamic SmartLink:

  1. Create a SmartDataObject that contains an internal procedure named ProcessCalc that has the following code:
  2. DEFINE INPUT PARAMETER pcCalcType AS CHARACTER NO-UNDO.
    
    CASE pcCalcType:
      WHEN "Totals":U THEN RUN calcTotals.
      WHEN "Discounts":U THEN RUN calcDiscounts.
    END CASE. 
    

  3. Create the code for the calcTotals and calcDiscounts procedures.
  4. Create a simple SmartObject called sCalcPanel.w that contains two buttons named Calculate Totals and Calculate Discounts, and add the following trigger code to these buttons:
  5. ON CHOOSE OF btnCalcTotals DO:
      PUBLISH "ProcessCalc":U (INPUT "Totals":U).
    END.
    
    ON CHOOSE OF btnCalcDiscounts DO:
      PUBLISH "ProcessCalc":U (INPUT "Discounts":U).
    END. 
    

  6. Create a SmartWindow.
  7. Drop the SmartDataObject onto the SmartWindow.
  8. Drop the sCalcPanel.w simple SmartObject onto the SmartWindow.
  9. Add a SmartLink as follows:
    1. Invoke the Link Advisor.
    2. Choose Add. The Add a SmartLink dialog box appears.
    3. From the Add a SmartLink dialog box, choose h_sCalcPanel as the Source.
    4. Choose Newº as the Link Type.
    5. Enter ProcessCalc as the New Link Type.
    6. From the Add a SmartLink dialog box, choose the SmartDataObject as the Target.
    7. Click OK.

When you run this application:

Thus the ProcessCalc SmartLink is dynamic, in the sense that the link name is not bound to a set of event procedure names that are statically defined in the SmartObjects.


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