Custom actions created with script extensions can generate code that calls procedures or functions. To generate an expression containing a procedure or function call, do the following:
-
Call the
Syntax.CreateInvoke
method to create a newInvokeSyntax
object. -
Specify the name of the desired function's procedure in the
InvokeName
property of the createdInvokeSyntax
object. -
Set the object’s
IsProperty
property to False. -
Use the
AddParameter
method of theInvokeSyntax
object to specify the parameter values for the routine call, if needed.
To get the actual script code corresponding to the resulting syntax object, process it with the Syntax.GenerateSource
method.
The example below demonstrates how to generate code that calls the Delay
routine:
JScript
function ShowCallStatement()
{
var oCall = Syntax.CreateInvoke();
oCall.InvokeName = "Delay";
oCall.IsProperty = false;
oCall.AddParameter(1000);
var strCode = Syntax.GenerateSource(oCall);
aqDlg.ShowMessage(strCode);
}
VBScript
Sub ShowCallStatement
Dim oCall, strCode
Set oCall = Syntax.CreateInvoke
oCall.InvokeName = "Delay"
oCall.IsProperty = False
oCall.AddParameter 1000
strCode = Syntax.GenerateSource(oCall)
aqDlg.ShowMessage strCode
End Sub
The generated code is as follows:
JavaScript, JScript
Delay(1000);
Python
Delay(1000)
VBScript
Call Delay(1000)
DelphiScript
Delay(1000);
C++Script, C#Script
Delay(1000);
See Also
Generating Script Code
Generating Object Method Calls
InvokeSyntax Object
Syntax.CreateInvoke Method