Try OpenEdge Now
skip to main content
Programming Interfaces
External Program Interfaces : ActiveX Control Support : Programming ActiveX controls in the AppBuilder : Using event procedures
 
Using event procedures
The AppBuilder provides definition templates for event procedures through the Triggers section of the Section Editor. (For more information, see Handling events.) In this application, the CSSpin control's SpinUp and SpinDown events are caught to advance or backup in the list of Customer records. These events also increment (SpinUp) or decrement (SpinDown) the spin button control Value property, which the application displays in the iRecordCount field.
This is the event procedure for the SpinUp event:
/* ************************ Control Triggers ************************ */
. . .

PROCEDURE custSpin.CSSpin.SPINUP .
/*------------------------------------------------------------------------
Purpose:
Parameters Required for this OCX:
None
Notes:
------------------------------------------------------------------------*/
  GET NEXT Dialog-Frame.
  IF NOT AVAILABLE Customer THEN DO:
    /* Control is incremented to last Customer + 1 */

    max-records = chCSSpin:Value - 1.
    chCSSpin:Value = 1.
    GET FIRST Dialog-Frame.
  END.
  RUN displayCustomer.
END PROCEDURE.
As you hold down the right-arrow button of the control, the control generates continuous SpinUp events. For each such event, this procedure reads the next query record and displays it. However, if the procedure tries to read beyond the last record in the query, it resets max-records to 1 less than the current Value property setting (the last record count).
It also resets the Value property to 1, wrapping around and restarting the upward query scan at the first record. Thus, the user can scan upward continuously through the query without reversing direction.
Note: The reason the application calculates a new value for max-records when it passes the last record is to get an updated result if records are deleted after NUM-RESULTS from the query is initially returned. However, note that the value might be inaccurate if records are deleted after the user encounters them. So, this is not a perfect solution.
This is the event procedure for the SpinDown event. As you hold down the left-arrow button of the control, the control generates continuous SpinDown events. For each such event, this procedure reads the previous query record and displays it. However, if the procedure tries to read before the first record in the query, it resets the current Value property setting to the known count of the last record in the query and restarts the downward query scan at the last record. For example:
/* ************************ Control Triggers ************************ */
. . .

PROCEDURE custSpin.CSSpin.SPINDOWN .
/*------------------------------------------------------------------------
Purpose:
Parameters Required for this OCX:
None
Notes:
------------------------------------------------------------------------*/
  GET PREV Dialog-Frame.
  IF NOT AVAILABLE Customer THEN DO:
    chCSSpin:Value = max-records.
    GET LAST Dialog-Frame.
  END.
  RUN displayCustomer.
END PROCEDURE.
Thus, the user can scan downward continuously through the query without reversing direction.
Note: The reason the application needs to set max-records from the number of query entries at the very start of execution (in the Main Block) might already be apparent. If the user begins by scanning downward from the first record, the application now knows the correct value to reset the record counter (Value property) to start the downward query scan at the last record.