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
InvokeSyntax
object using theSyntax.CreateInvoke
method. -
Use the
ClassValue
andInvokeName
of the createdInvokeSyntax
object to specify the object that contains the property to be referred and the property name, respectively. -
Set the
IsProperty
property of theInvokeSyntax
object to True. -
If the target property uses parameters, use the
AddParameter
method of theInvokeSyntax
object 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