Generating Assignment Statements

Applies to TestComplete 15.70, last modified on December 17, 2024

Custom actions created with script extensions can generate code that assigns values to variables or object properties. To generate an assignment statement, do the following:

After you have configured the AssignSyntax object, you can pass it to the Syntax.GenerateSource method to get the actual script code of the assingment statement.

The following example demonstrates how you can generate code that assigns the value True to the MyVar variable:

JScript

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

  var oAssignment = Syntax.CreateAssign();
  oAssignment.Left = oVarName;
  oAssignment.Right = true;

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

VBScript

Sub ShowAssignmentStatement
  Dim oVarName, oAssignment, strCode

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

  Set oAssignment = Syntax.CreateAssign
  oAssignment.Left = oVarName
  oAssignment.Right = True

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

The generated code is as follows:

JavaScript, JScript

MyVar = true;

Python

MyVar = True

VBScript

MyVar = True

DelphiScript

MyVar := true;

C++Script, C#Script

MyVar = true;

See Also

Generating Script Code
Generating Variable Expressions
Generating Object Property Expressions
AssignSyntax Object
CreateAssign Method

Highlight search results