Custom actions created with script extensions can generate script code that use calls to object methods. To generate an expression that contains a call to an object’s method, perform these steps:
-
Create a new
InvokeSyntaxobject using theSyntax.CreateInvokemethod. -
Use the
ClassValueandInvokeNameof the createdInvokeSyntaxobject to specify the object that contains the desired method and the method name, respectively. -
Set the
IsPropertyproperty of theInvokeSyntaxobject to False. -
If the target method uses parameters, use the
AddParametermethod of theInvokeSyntaxobject to specify the parameter values to be used in the generated code.
After you have configured the InvokeSyntax object, you can pass it to the Syntax.GenerateSource method to get the actual script code of the method call.
The example below demonstrates how you can generate a Log.Message method call:
JScript
function ShowMethodCallStatement()
{
var oMethodCall = Syntax.CreateInvoke();
oMethodCall.ClassValue = "Log";
oMethodCall.InvokeName = "Message";
oMethodCall.IsProperty = false;
oMethodCall.AddParameter("Test");
var strCode = Syntax.GenerateSource(oMethodCall);
aqDlg.ShowMessage(strCode);
}
VBScript
Sub ShowMethodCallStatement
Dim oMethodCall, strCode
Set oMethodCall = Syntax.CreateInvoke
oMethodCall.ClassValue = "Log"
oMethodCall.InvokeName = "Message"
oMethodCall.IsProperty = False
oMethodCall.AddParameter "Test"
strCode = Syntax.GenerateSource(oMethodCall)
aqDlg.ShowMessage strCode
End Sub
The generated code is as follows:
JavaScript, JScript
Log.Message("Test");
Python
Log.Message("Test")
VBScript
Call Log.Message("Test")
DelphiScript
Log.Message('Test');
C++Script, C#Script
Log["Message"]("Test");
See Also
Generating Script Code
Generating Routine Calls
Generating Object Property Expressions
Generating Process, Window and Onscreen Object References
InvokeSyntax Object
Syntax.CreateInvoke Method
