Release 10.1A: OpenEdge Development:
AppBuilder

> ## Configuring an ActiveX object instance

> Because OCX controls are not native to the OpenEdge 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()`.

> 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:

> 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.

> 6. Choose the New button. The New Procedure dialog box opens:

> 7. 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.

> 8. Insert these lines of code:

>     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.

> 9. Change Section to Definitions and define a variable to represent the current spin value:

>     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.
>     */

> 10. Change Section to Triggers, and choose New. The dialog box will open:

> 11. Select OCX.SpinUp and choose OK. Section Editor generates a new stub event handler. Insert these lines of code to complete it:

>     iCurrSpinValue = chiSpinBox:CSSpin:VALUE.
>     MESSAGE "Current value: " iCurrSpinValue.

> 12. 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 © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095