Invoking methods of OLE automation objects
Methods of OLE automation objects are invoked by their unique name or DISPID. An OleAutomationObject has instance methods that are used to call a method of an OLE automation object. The methods are invoke:withArguments: and invoke:withArguments:returnType:.
Both methods take as a first parameter the name (or DISPID) of the method to invoke, and as a second parameter an array of parameters to be passed to the method.
The invoke:withArguments: returns the result of the OLE method sent, or nil if there was an error.
The value returned from invoke:withArguments:returnType: depends on the value of the returnType: parameter, as described below. A false value returnType: is required because some automation servers, such as Microsoft Word, have methods that fail unless their return values are not requested. The values of returnType include the following:
true
Answers the return value of the OLE method
false
Ignores the return value of the OLE method
Note:
If an error is indicated with a nil return from one of the OLE automation objects invoke methods, a String describing the error may be obtained by sending the lastErrorString message to the OleAutomationObject.
Smalltalk objects returned from an OleAutomationObject invoke method are converted from their OLE types to equivalent Smalltalk types. Likewise, Smalltalk objects passed as parameters to an invoke method are converted to their OLE equivalent types based on their Smalltalk class. These conversions are supported only for the simple Smalltalk objects listed below. The Smalltalk classes supported for automatic conversion to and from OLE types include the following:
•Integer
•Float
•String
•Boolean
•OleAutomationObject
Note:
If a parameter to one of the invoke methods cannot be represented in one of the supported types named above, an initialized instance of OSVariantarg may be used. Likewise, a return value of an invoke method is either one of the supported types or an instance of OSVariantarg.
As an example of using the invoke methods on an OleAutomationObject, consider the following code fragment that opens Microsoft Word, inserts some text, moves the text insertion point, and selects the text:
| wordBasic text |
wordBasic := OleAutomationObject createObject: 'Word.basic'.
text := ' A small amount text for Word.'.
wordBasic
invoke: 'FileNew' withArguments: #();
invoke: 'CharRight' withArguments: #(1);
invoke: 'Insert' withArguments: (Array with: text) returnType: false;
invoke: 'ExtendSelection' withArguments: #() returnType: false;
invoke: 'CharLeft' withArguments: (Array with: text size).
Last modified date: 01/29/2015