Progress
AppBuilder
Developer’s Guide


Configuring an ActiveX Object Instance

Because OCX controls are not native to the Progress system, configuring them is a slightly more complicated process than configuring a comparable 4GL widget. AppBuilder generates a control_load() procedure to handle generic initialization of OCX objects. That procedure performs three tasks:

  1. Creates a COM–HANDLE variable and initializes it with the handle of the COM-object layer of the Control Frame
  2. Calls the LoadControls() method
  3. Calls the optional procedure initialize-controls()

At this point, you must take over. You must perform some number of tasks that are object-dependent. In general, you must:

  1. Assign a meaningful identifier to the object—or, more exactly, to its Control Frame. You need do nothing with the identifier (the Name property) of the OCX object itself.
  2. Write the initialize-controls() procedure if you want to do special initialization.
  3. Select the events you wish to handle for this object and create procedures to do that.
  4. Size and position the object image within the workspace.

The following walkthrough presumes you are placing an instance of the Spin Control that AppBuilder supplies in the Objects Palette. Follow these steps:

  1. Create a Window workspace and set the Message Area property, so that the workspace will be able to display messages conveniently.
  2. Click on the Spin Control tool icon in the Objects Palette:
  3. Move your mouse cursor over a bare spot in your workspace and click to place the instance. The default size will probably be too large—temporarily resize it now:
  4. Note that AppBuilder’s main window displays two Object identifiers. Replace the editable identifier (CtrlFrame) with one that is more meaningful in the context of your application. For this example, use iSpinBox:
  5. Press F2 to run the workspace momentarily, which forces AppBuilder to create the control_load() procedure. (This is not a step you need normally take; it is included here only for the sake of the example.) Stop the run as soon as you like. Choose Window Code Section Editor. When the editor window opens, select Procedures as the Section, and control_load as the procedure:
  6. Note these lines of code:

    ASSIGN
      chiSpinBox = iSpinBox:COM-HANDLE 
      UIB_S = chiSpinBox:LoadControls( OCXFile, "iSpinBox":U )
    .
    RUN initialize-controls IN THIS-PROCEDURE NO-ERROR. 
    

    AppBuilder creates the COM–HANDLE identifier by prepending the digraph “ch” to whatever identifier you assigned to the Control Frame object. In this case, the Control Frame identifier is iSpinBox, so the handle is chiSpinBox. AppBuilder initializes the handle by assigning the Control Frame’s COM–HANDLE property.

    AppBuilder then uses that COM–HANDLE to call LoadControls(), and finally inserts a generic call to the optional initialize–controls() routine.

  7. Choose the New button. The New Procedure dialog box opens:
  8. Type in initialize–controls as the procedure name. (Be careful not to use an underscore, if you are used to writing C.) Set Type to Procedure, if necessary, and choose OK. Section Editor generates a new stub routine.
  9. Insert these lines of code:
  10. ASSIGN
      chiSpinBox:CSSpin:Value = 5
      chiSpinBox:CSSpin:Max = 1000
      chiSpinBox:CSSpin:Min = -500
      chiSpinBox:CSSpin:Increment = 100.
    MESSAGE "Control Initialized" . 
    

    Note how the code refers to the properties. The reference is not via the COM–HANDLE variable directly because that refers to the COM object layer in the adaptive interface, not to the ActiveX object itself. You must use an indirect reference, combining the COM–HANDLE , OCX, and property identifiers:

    NOTE: The color-coding and all-caps appearance of certain properties, as shown here, is an artifact of the Section Editor settings. Those attributes are not significant in any way, and you can change them to suit yourself.

  11. Change Section to Definitions and define a variable to represent the current spin value:
  12. DEFINE VARIABLE iCurrSpinValue AS INTEGER INITIAL 0.
    /* 
    ** Note the initialization to 0.  This is compile-time
    ** initialization, done for safety’s sake.
    ** It is overridden at run time by the initialization to 5.
    */ 
    

  13. Change Section to Triggers, and choose New. The dialog box will open:
  14. Select OCX.SpinUp and choose OK. Section Editor generates a new stub event handler. Insert these lines of code to complete it:
  15. iCurrSpinValue = chiSpinBox:CSSpin:VALUE.
    MESSAGE "Current value: " iCurrSpinValue. 
    

  16. Choose New again, and create a trigger for the OCX.SpinDown event. Use the same code.

Run the workspace. You should see the Spin Control initialized to 5, and your “Control Initialized” message:

When you operate the arrowhead buttons in the control, you should see the values change in increments of 100, to the limits –495 and 905:


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