How Do I Call a COM Object Method? (Magic xpa 2.x)
Once your COM object is declared, you can call it much as you would call a program or a subtask. However, a different operation is used, Invoke, to differentiate the call from a call within Magic xpa.
-
Open up a line in the appropriate logic unit.
-
Set the operation to invoke by typing I or selecting from the drop-down list.
-
Set the invoke type to COM by typing C or selecting from the drop-down list. Tab.
-
Zoom to bring up the COM object dialog box.
-
Zoom from the Object field to select your COM object.
-
Select Invoke Method from the drop-down list on the Option field.
-
Zoom from the Method field to select the method you want to invoke.
-
Press Escape to close the COM Object dialog box. Tab to the Arguments field, and zoom.
-
Now you will be presented with a list of arguments for this method. Note that you get a lot of information about these arguments in the list, such as whether it is an input or output parameter, whether it is optional or not, and the data type.
If you click on the box in the Create column, Magic xpa will create a variable that matches the argument data type. However, Magic xpa also does a lot of the data conversion for you, so you don’t have to be as exact about the data types as you would if you were using other programming tools. For instance, this example uses the VT_VARIANT type, which, if you study COM objects, means you need to pass in a pointer. But we just pass it an expression (which happens to be the number zero in this case) and Magic xpa does the rest of the work. Similarly, if you are passing in a numeric value, you needn’t worry about issues such as whether the number is float or long or packed integer or whatever.
Now you have created a call to a method in your COM object.
Hint: To save time, you can copy Invoke COM operations to start the next one. This is particularly useful if you are invoking the same method over and over, as will happen when, for instance, you are formatting a Word document using COM objects and need to add paragraph breaks. Use Ctrl+Shift+R to copy an existing operation, or Ctrl+C Copy and Ctrl+V Paste.