To invoke a method of an ActiveX control on a WS window, you first need a handle for it, also known as an oref. Think of this as a pointer to the control. Within the controls own Action Logic (AL) you can use the macro %%I (thats a capital i). Outside the controls AL the macro is not available, so if you need to invoke the method elsewhere (for example, on the Push event of a Button on your window), place an oref into an M local. A good place is in the ActiveX controls Create logic:
Note the use of ZSET, which copies orefs. Dont NEW MyCtl within the Create logic, else itll vanish as soon as the AL section quits.
Its good practice to tidy this variable up in the matching Destroy section:
Now when you want to invoke a method, you have a starting-point. Next question is, do you care about the return-value (if any) of the method? If you do, the syntax for a parameterless method called MyMethod would be:
or, if the method returns an object,
Naturally, if this is being done within the controls own AL, you can use %%I instead:
When the return-value of the method is not needed, you can use:
To pass parameters to the method, list them in the natural way:
As an alternative to positional parameters, you can use named parameters. Though less efficient, it may improve legibility of code, and can be handy in skipping optional parameters:
Now, how to handle output (or bi-directional) parameters? As an Mster might expect, you use the dot-prefix to pass a variable by reference. To use a real-world example:
Of course, the variable F1Book1 must have been ZSET to %%I for the control, and nSel to the input value. But what about the four p-variables? In this case, the method doesnt expect any input values on these parameters, but does want them to be of type Long. The notion of variable type is foreign to M, but MSM implements some simple rules when interfacing to COM objects such as ActiveX controls. When passing a variable by-reference as a method parameter, the nature of the initial contents of the variable dictate the type its passed as. If the variable contains a string, its passed as a String (technically, VT_BSTR). If its set to an integer, its passed as a Long (VT_I4), and if to a fractional number, as a Double (VT_R8). If its undefined its passed as omitted (VT_ERROR). If the M variable contained an oref its passed as an Object (VT_DISPATCH).
So in this case, the following is required before the method call:
Unfortunately, if your method requires another type of by-ref parameter, such as Integer (VT_I2) or Single (VT_R4) then youre likely to get a Type mismatch error when you try to invoke the method.