Programming the ActiveX control
You make an ActiveX control do its job by programming it in
scripts, setting its properties, and calling its functions. Depending
on the interface provided by the ActiveX control developer, a single
function call might trigger a whole series of activities or individual
property settings, and function calls may let you control every
aspect of its actions.
An ActiveX control is always active—it does not contain
an object that needs to be opened or activated. The user does not
double-click and start an OLE server. However, you can program the
DoubleClicked or any other event to call a function that starts
ActiveX control processing.
Setting properties in scripts
Programming an ActiveX control is the same as programming
automation for insertable objects. You use the container’s Object property
to address the properties and functions of the ActiveX control.
This syntax accesses a property value. You can use it wherever
you use an expression. Its datatype is Any.
When the expression is evaluated, its value has the datatype of
the control property:
1 |
<span>olecontrol</span>.<span>Object</span>.<span>ocxproperty</span> |
This syntax calls a function. You can capture its return value
in a variable of the appropriate datatype:
1 |
{ <span>value</span> } = <span>olecontrol</span>.<span>Object</span>.<span>ocxfunction</span> ( {<span> argumentlist </span>} ) |
Errors when accessing properties
The PowerBuilder compiler does not know the correct syntax
for accessing properties and functions of an ActiveX control, so
it does not check any syntax after the Object property. This provides
the flexibility you need to program any ActiveX control. But it
also leaves an application open to runtime errors if the properties
and functions are misnamed or missing.
PowerBuilder provides two events (ExternalException and Error)
for handling OLE errors. If the ActiveX control defines a stock
error event, the PowerBuilder OLE control container has an additional
event, ocx_event. These events allow you to intercept and
handle errors without invoking the SystemError event and terminating
the application. You can also use a TRY–CATCH exception
handler.
For more information, see “Handling errors”.
Using events of the ActiveX control
An ActiveX control has its own set of events, which PowerBuilder
merges with the events for the custom control container. The ActiveX
control events appear in the Event List view with the PowerBuilder
events. You write scripts for ActiveX control events in PowerScript
and use the Object property to refer to ActiveX control properties
and methods, just as you do for PowerBuilder event scripts.
The only difference between ActiveX control events and PowerBuilder
events is where to find documentation about when the events get
triggered. The ActiveX control provider supplies the documentation
for its events, properties, and functions.
The PowerBuilder Browser provides lists of
the properties and methods of the ActiveX control. For more information,
see “OLE information in the Browser “.
If you install an updated version of an ActiveX control and
it has new events, the event list in the Window painter does not
add the new events. To use the new events, you have to delete and
recreate the control, along with the scripts for existing events.
If you do not want to use the new events, you can leave the control
as is—it will use the updated ActiveX control with the
pre-existing events.