Syntax.CreateCollection Method

Applies to TestComplete 15.48, last modified on March 01, 2023

Description

This method creates and returns a new CollectionSyntax object, which is a syntax element corresponding to a collection of code statements. For example:

JavaScript, JScript

Answer = 42;
Log.Message(Answer);

Python

Answer = 42;
Log.Message(Answer);

VBScript

Answer = 42
Log.Message Answer

DelphiScript

Answer := 42;
Log.Message(Answer);

C++Script, C#Script

Answer = 42;
Log["Message"](Answer);

After creating a CollectionSyntax object instance, you can use its Add method to add syntax elements to this collection.

Declaration

Syntax.CreateCollection()

Result A CollectionSyntax object

Applies To

The method is applied to the following object:

Result Value

A CollectionSyntax object that corresponds to a collection of code statements.

Example

The following example generates the code given in the Description section and displays it in a message box:

JScript

function ShowStatementCollection()
{
  var oCollection = Syntax.CreateCollection();

  var oVarName = Syntax.CreateInvoke();
  oVarName.InvokeName = "Answer";
  oVarName.IsProperty = true;

  var oAssignment = Syntax.CreateAssign;
  oAssignment.Left = oVarName;
  oAssignment.Right = 42;

  oCollection.Add(oAssignment);

  var oMethodCall = Syntax.CreateInvoke();
  oMethodCall.ClassName = "Log";
  oMethodCall.InvokeName = "Message";
  oMethodCall.IsProperty = false;
  oMethodCall.AddParameter(oVarName);

  oCollection.Add(oMethodCall);

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

VBScript

Sub ShowStatementCollection
  Dim oCollection, oVarName, oAssignment, oMethodCall, strCode

  Set oCollection = Syntax.CreateCollection

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

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

  oCollection.Add oAssignment

  Set oMethodCall = Syntax.CreateInvoke
  oMethodCall.ClassName = "Log"
  oMethodCall.InvokeName = "Message"
  oMethodCall.IsProperty = False
  oMethodCall.AddParameter oVarName

  oCollection.Add oMethodCall

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

See Also

CollectionSyntax Object
CreateAssign Method
CreateCondition Method
CreateInvoke Method
CreateIf Method
CreateVarDef Method
AddSyntaxToScript Method

Highlight search results