Custom actions created with script extensions can generate script code that refers to object properties in order to get or set their values. To generate an expression that refers to an object’s property, follow these steps:
-
Create a new
InvokeSyntaxobject using theSyntax.CreateInvokemethod. -
Use the
ClassValueandInvokeNameof the createdInvokeSyntaxobject to specify the object that contains the property to be referred and the property name, respectively. -
Set the
IsPropertyproperty of theInvokeSyntaxobject to True. -
If the target property uses parameters, use the
AddParametermethod of theInvokeSyntaxobject to specify the parameter values to be used in the generated code.
After configuring the InvokeSyntax object, you can pass it to the Syntax.GenerateSource method to get the actual script code of the property expression.
The following example demonstrates how to generate an expression that refers to the Sys.Clipboard property:
JScript
function ShowPropertyStatement()
{
var oPropName = Syntax.CreateInvoke();
oPropName.ClassValue = "Sys";
oPropName.InvokeName = "Clipboard";
oPropName.IsProperty = true;
var strCode = Syntax.GenerateSource(oPropName);
aqDlg.ShowMessage(strCode);
}
VBScript
Sub ShowPropertyStatement
Dim oPropName, strCode
Set oPropName = Syntax.CreateInvoke
oPropName.ClassValue = "Sys"
oPropName.InvokeName = "Clipboard"
oPropName.IsProperty = True
strCode = Syntax.GenerateSource(oPropName)
aqDlg.ShowMessage strCode
End Sub
The generated code is as follows:
JavaScript, JScript
Sys.Clipboard;
Python
Sys.Clipboard
VBScript
Sys.Clipboard
DelphiScript
Sys.Clipboard;
C++Script, C#Script
Sys["Clipboard"];
See Also
Generating Script Code
Generating Variable Expressions
Generating Object Method Calls
Generating Process, Window and Onscreen Object References
InvokeSyntax Object
Syntax.CreateInvoke Method
