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:
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:
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).