PropertyCount Property

Applies to TestComplete 15.47, last modified on January 20, 2023

The object-driven testing (ODT) functionality is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can create custom classes in your scripts. For more information, see Alternatives to the ODT functionality.

Description

Use the Object.PropertyCount property to get the total number of properties in the specified object.

Declaration

ObjectObj.PropertyCount

Read-Only Property Integer
ObjectObj An expression, variable or parameter that specifies a reference to an Object object

Applies To

The property is applied to the following object:

Property Value

The total number of properties in the object.

Remarks

Note that this number will differ from the number of properties in the class on which the object is based if you add some properties to the object after it is created.

Example

The following code snippet declares a new class, adds several properties to it and creates an object based on the declared class. After that, it adds another property to the object and iterates through the object’s properties posting information on them to the test log.

JavaScript, JScript

function ObjectSample()
{

ODT.Data.Clear();
ODT.Classes.Clear();
  var NewClass, MyObject, Prop;
  // Declares a new class
  NewClass = ODT.Classes.Declare("NewClass")
  // Adds properties to the declared class
  NewClass.AddProperty("ClassProperty1", "Value1");
  NewClass.AddProperty("ClassProperty2", "Value2");

  // Creates an object based on the declared class
  MyObject = ODT.Classes.New("NewClass");
  // Adds a property to the object
  MyObject.AddProperty("ObjectProperty", "Value3");

  // Iterates through the object’s properties
  for (var i = 0; i < MyObject.PropertyCount; i++)
  {
    // Obtains the object’s property by its index
    Prop = MyObject.Properties(i);

    // Posts information on the property to the test log
    Log.AppendFolder(Prop.Name);
    Log.Message("Enabled: " + Prop.Enabled);
    Log.PopLogFolder();
  }

}

VBScript

Sub ObjectSample

ODT.Data.Clear
ODT.Classes.Clear
  ' Declares a new class
  Set NewClass = ODT.Classes.Declare("NewClass")
  ' Adds properties to the declared class
  Call NewClass.AddProperty("ClassProperty1", "Value1")
  Call NewClass.AddProperty("ClassProperty2", "Value2")

  ' Creates an object based on the declared class
  Set MyObject = ODT.Classes.New("NewClass")
  ' Adds a property to the object
  Call MyObject.AddProperty("ObjectProperty", "Value3")

  ' Iterates through the object’s properties
  For i = 0 To MyObject.PropertyCount - 1
    ' Obtains the object’s property by its index
    Set Prop = MyObject.Properties(i)

    ' Posts information on the property to the test log
    Log.AppendFolder Prop.Name
    Log.Message "Enabled: " & Prop.Enabled
    Log.PopLogFolder
  Next

End Sub

DelphiScript

procedure ObjectSample();

var NewClass, MyObject, i, Prop;
begin
ODT.Data.Clear;
ODT.Classes.Clear;
  // Declares a new class
  NewClass := ODT.Classes.Declare('NewClass');
  // Adds properties to the declared class
  NewClass.AddProperty('ClassProperty1', 'Value1');
  NewClass.AddProperty('ClassProperty2', 'Value2');

  // Creates an object based on the declared class
  MyObject := ODT.Classes.New('NewClass');
  // Adds a property to the object
  MyObject.AddProperty('ObjectProperty', 'Value3');

  // Iterates through the object’s properties
  for i := 0 to MyObject.PropertyCount - 1 do
  begin
    // Obtains the object’s property by its index
    Prop := MyObject.Properties[i];

    // Posts information on the property to the test log
    Log.AppendFolder(Prop.Name);
    Log.Message('Enabled: ' + aqConvert.VarToStr(Prop.Enabled));
    Log.PopLogFolder();
  end;

end;

C++Script, C#Script

function ObjectSample()
{

ODT["Data"]["Clear"]();
ODT["Classes"]["Clear"]();
  var NewClass, MyObject, Prop;
  // Declares a new class
  NewClass = ODT["Classes"]["Declare"]("NewClass")
  // Adds properties to the declared class
  NewClass["AddProperty"]("ClassProperty1", "Value1");
  NewClass["AddProperty"]("ClassProperty2", "Value2");

  // Creates an object based on the declared class
  MyObject = ODT["Classes"]["New"]("NewClass");
  // Adds a property to the object
  MyObject["AddProperty"]("ObjectProperty", "Value3");

  // Iterates through the object’s properties
  for (var i = 0; i < MyObject["PropertyCount"]; i++)
  {
    // Obtains the object’s property by its index
    Prop = MyObject["Properties"](i);

    // Posts information on the property to the test log
    Log["AppendFolder"](Prop["Name"]);
    Log["Message"]("Enabled: " + Prop["Enabled"]);
    Log["PopLogFolder"]();
  }

}

See Also

Properties Property
MethodCount Property
MethodCount Property

Highlight search results