Generating Variable Expressions

Applies to TestComplete 15.42, last modified on August 01, 2022

Custom actions created with script extensions can generate script code that uses variables. After creating a variable declaration, you can generate code that uses this variable. To generate an expression containing a variable name, follow these steps:

The resulting InvokeSyntax object can be used to create more complex expressions and statements, for example, assignment statements (see Generating Assignment Statements).

The following example demonstrates how to generate an expression that refers to the MyVar variable:

JScript

function ShowPropertyStatement()
{
    var oVarName = Syntax.CreateInvoke();
    oVarName.InvokeName = "MyVar";
    oVarName.IsProperty = true;

    var strCode = Syntax.GenerateSource(oVarName);
    aqDlg.ShowMessage(strCode);
}

VBScript

Sub ShowPropertyStatement
    Dim oVarName, strCode

    Set oVarName = Syntax.CreateInvoke
    oVarName.InvokeName = "MyVar"
    oVarName.IsProperty = True

    strCode = Syntax.GenerateSource(oVarName)
    aqDlg.ShowMessage strCode
End Sub

See Also

Generating Script Code
Generating Variable Declarations
Generating Object Property Expressions
InvokeSyntax Object
CreateInvoke Method

Highlight search results