Assignments among OLEControl, OLECustomControl, and OLEObject datatypes
You cannot assign an OLE control (object type OLEControl)
or ActiveX control (object type OLECustomControl) to an OLEObject.
If the vendor of the control exposes a programmatic identifier
(in the form vendor.application), you can specify
this identifier in the ConnectToNewObject function
to connect to the programmable interface without the visual control. For
an ActiveX control with events, this technique makes the events unavailable.
ActiveX controls are not meant to be used this way and would not be
useful in most cases.
You can assign the Object property of an OLE control to an
OLEObject variable or use it as an OLEObject in a function.
For example, if you have an OLEControl ole_1 and
an OLECustomControl ole_2 in a window
and you have declared this variable:
1 |
OLEObject oleobj_automate |
then you can make these assignments:
1 |
oleobj_automate = ole_1.Object<br>oleobj_automate = ole_2.Object |
You cannot assign an OLEObject to the Object property of an
OLE control because it is read-only. You cannot make this assignment:
1 |
ole_1.Object = oleobj_automate //Error! |
Events for OLEObjects
You can implement events for an OLEObject by creating a user
object that is a descendant of OLEObject. The SetAutomationPointer PowerScript
function assigns an OLE automation pointer to the descendant so
that it can use OLE automation.
Suppose oleobjectchild is a descendant
of OLEObject that implements events such as the ExternalException
and Error events. The following code creates an OLEObject and an
instance of oleobjectchild, which is a user
object that is a descendant of OLEObject, connects to Excel, then
assigns the automation pointer to the oleobjectchild:
1 |
OLEObject ole1<br>oleobjectchild  oleChild<br> <br>ole1 = CREATE OLEObject<br>ole1.ConnectToNewObject( "Excel.Application")<br> <br>oleChild = CREATE oleobjectchild<br>oleChild.SetAutomationPointer( ole1 ) |
You can now use olechild for automation.