As mentioned in the previous section, QOLEOBJECT implements an automation
controller. This component works similarly to VB (no, VB does not have a
QOLEOBJECT component), except for a few things which are either implemented in
another way or is not yet supported. Let's look at some examples comparing the 2
methods:
' Both examples invoke MS WORD
' in VB
DIM Obj AS OBJECT
Set Obj = CreateObject("Word.Basic")
' or just DIM Obj AS Word.Basic
Obj.AppShow
' in Rapid-Q
DIM Obj AS QOLEOBJECT
Obj.CreateObject("Word.Basic")
Obj.AppShow
Note that type checking is off for OBJECT and QOLEOBJECT, so when you
invoke Obj.AppShow this calls the method AppShow in MS
WORD. You may notice that Rapid-Q also supports the Invoke method. This
is to eliminate ambiguity but also to provide a work around. So what if MS WORD
has a method called CreateObject? In Rapid-Q this causes a problem since
CreateObject is a valid method of QOLEOBJECT, so that method will be called, not
the one in MS WORD. The work around is to use the Invoke method. ' in Rapid-Q
DIM Obj AS QOLEOBJECT
Obj.CreateObject("Word.Basic")
Obj.Invoke("CreateObject") ' Call CreateObject method in MS WORD
Obviously you shouldn't run the above example, MS WORD doesn't have a
CreateObject method, but you get the idea. Setting and getting properties can be
done similarly: ' in Rapid-Q
DIM Obj AS QOLEOBJECT
Obj.CreateObject("Gif89.Gif89.1")
Obj.AutoStart = 1
Obj.Invoke("AutoStart") = 1 ' this also works
So what's not supported in Rapid-Q? Several data types and arrays are not
supported yet, as well as events. Also there isn't a "set" method available. ie:
' in VB
DIM ADOCommand AS ADODB.Command
DIM ADOConnection AS ADODB.Connection
set ADOCommand.ActiveConnection = ADOConnection
The line in red is not yet available in Rapid-Q. See the Appendix section
on QOLEOBJECT, you will find a method called InvokeCopy which does the
samething, but unfortunately isn't fully functional as of this writing.
15.3 About QOLECONTAINER
QOLECONTAINER is basically a container for embedding ActiveX components or
Active documents. This component is very similar to QOLEOBJECT, it is again type
check free, so you can automate the control like you would automating servers.
You may find yourself using the Invoke method more often than not, since
QOLECONTAINER does have a lot of properties and methods already defined. Another
way to avoid this problem is the assign the Container method of
QOLEOBJECT. This creates a reference to the object, and so you can use
QOLEOBJECT to automate the control. For those that aren't familiar, ActiveX
controls are reusable visual controls which are heavily used in VB. Again, the
limitations are obvious, Rapid-Q doesn't support ActiveX events, type libraries,
and a few others mentioned before. '-- A short example
DIM Form AS QFORM
DIM Obj AS QOLECONTAINER
Obj.Parent = Form
Obj.CreateObject("gif89.gif89.1")
Since an ActiveX control is a visible component, you'll note that the
QOLECONTAINER requires a parent property. You'll also have to be wary of the
fact that the ActiveX component could update/refresh the component even before
the form is shown, so you'll receive a Can't focus a
disabled or invisible window when that happens. QOLECONTAINER has an
AutoShow property which can be set to False meaning that the ActiveX
control should not be displayed when created. You can use the method Show
of QOLECONTAINER to display the control at anytime after creating the object.
There is also another way to avoid the error message from popping up, see the
Appendix section on QOLECONTAINER for a complete example.