>>  <<  Ndx  Usr  Pri  Phr  Dic  Rel  Voc  !:  wd  Help  User

J OLE/OCX Client

J interacts with OLE and OCX controls using the Window Driver. You need a parent window to display the control, and you then create and use a OLE/OCX control in much the same way as for any other child control. You can use both standard and OLE/OCX controls on the same form.

wd 'cc tree ocx:comctl.treectrl.1'
wd 'cc xl oleautomation:excel.application'

OCX and OLE controls are not distributed with J. Some OCX and OLE controls are included with Windows, and with software such as Visual Basic. In some cases, these are subsets or earlier versions of the full systems obtainable from the original manufacturer. For serious use, we recommend you purchase the most recent versions of the controls, which will then include full documentation and support.

To see which OCX controls are available, create a new form using the Form Editor, then click New for new control, and select class OCX.

OLE controls are not supported by the Form Editor and should be added directly in the form_run verb. The names of the OLE controls that are available are not visible from J.

An OCX or OLE control is a child on a form that contains an object named base. This base object can contain other objects. For example the base object could contain a font object. An object is identified by the child id and the name of the object. The name temp refers to a contained object that has been returned by a method or property. The temp object is automatically released and reset whenever a new object is returned. The oleid command gives the temp object a name and makes it permanent.

Each control has a specific list of methods, properties and events (for OCX controls). The properties define the way the control is set up. The events are the events that the OCX control can generate. When you create a control, you typically set various properties, and register various events that you want to be notified of. When the control is in use, you retrieve information from the control by either reading the value of its properties, or by receiving event notifications.

wd commands for OLE/OCX controls

oledlg id
Run the OCX property dialog. The state can be saved with the olesave command.

oleenable id eventname [bool]
Enable/disable OCX event. You must enable an event in order to trigger an event in J.

oleget id objectname property
Return value of a property. Objectname is base, temp, or a name set with oleid. If the result is an object, it is set as the temp object. This allows a series of wd commands that use the temp object to get the next object.

oleinfo id
Return information about events, methods, properties, and constants.

oleload id filename
Initialize properties from a file created by olesave. An oleload should only be done once before it is shown.

olemethod id objectname method parameters....
Run a method.

, is an elided parameter. A wd parameter of , is the same as "", except it is treated as an elided parameter where appropriate.

Some methods distinguish between a numeric parameter and a string. A simple (not delimited) string that is an integer is treated as an integer. If you want 23 to be treated as a string, use "23";.

If the result is an object, it is set as the temp object.

An object parameter is indicated by a simple parameter of the form:
object:formid.childid.objectname

A picture object parameter is indicated by a simple parameter of the form:
picture:filename

olesave id filename
Save properties in a file that can be used to initialize a control after it is created.

oleset id objectname property value
Set property value.

Objectnames
An OLE or OCX base object can contain other objects.

For example, many OCX controls contain a Font object that is returned by the font property.

wd 'oleget ocx base font' get font object as temp

wd 'oleget ocx temp fontsize' get font size
8.5

wd 'oleget ocx temp fontname' get font name
Times New Roman

wd 'oleset ocx temp Times New Roman;oleset ocx temp fontsize 20' set font

OCX Events
An OCX event is signalled as a button event. For example, form abc, OCX id spin, signals sysevent abc_spin_button. The name sysocx is assigned the OCX event name.

Example: Spinbutton Control
To illustrate these commands, we use the Outrider Systems SPIN32.OCX, a simple control that is ideal for experimentation. We assume you have this control installed on your system.

First try reading the OCX information (if this fails, you do not have the SpinButton installed). This returns a text description of properties, methods and events:

load 'packages\ocx\ocxutil.js' load OCX utilities
ocxinfo 'spin.spinbutton'
NB. event: SpinDown
NB. prototype: void SpinDown ()
NB. help: Occurs when the user clicks one of the arrows...

NB. event: SpinUp
...

Next, load the spinbutton demo, as follows:

   load 'examples\ocx\misc\spin.js'

Click on the spinbutton to change the text field. Click on the About button to display the about box from Outrider, and the Dialog button to view and change the OCX properties.

Note that to see events from the spinbutton, you use the oleenable command when initializing the form, i.e.

spin_run=: 3 : 0
wd SPIN
showpay''
wd 'oleenable sx spindown'
wd 'oleenable sx spinup'
wd 'pshow;'
)

The About button invokes the OCX's aboutbox method:

spin_about_button=: 3 : 0
wd 'olemethod sx base aboutbox'
)

The Dialog button invokes the oledlg command:

spin_dialog_button=: 3 : 0
wd 'oledlg sx'
)

A press of the spinbutton, invokes the spinbutton handler:

spin_sx_button=: 3 : 0
if. sysocx-:'spinup' do.
  PAYNDX=: 4|>:PAYNDX
else.
  PAYNDX=: 4|<:PAYNDX
end.
showpay''
)

This handler checks the value of sysocx and adjusts the text field accordingly.


>>  <<  Ndx  Usr  Pri  Phr  Dic  Rel  Voc  !:  wd  Help  User