GetSectionName Method

Applies to TestComplete 14.92, last modified on September 16, 2021

Description

Returns the name of a subsection in the current section. The sought-for subsection is identified by its index in the subsection collection of the current section. To get the number of subsections in this collection, use the SectionCount property. To get the Section object for the subsection by its index, use the GetSubSectionByIndex method.

If the subsection you want does not exist, the GetSectionName method will create it.

Declaration

ProgObj.GetSectionName(Index)

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
Index [in]    Required    Integer    
Result String

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

Index

Specifies the index of the desired subsection. The index is zero-based, that is, the first subsection has index 0, the second - 1, and so on. Index of the last subsection is SectionCount-1.

Result Value

The name of the specified subsection.

Example

The following code snippet uses the GetSectionName method to obtain the names of the subkeys that belong to the specified Windows registry key. Then, it posts these names to the test log.

JavaScript, JScript

function Test()
{
  var Key, Name, SubKeyName, Count;
  // Gets an object for the Windows system registry key
  Key = Storages.Registry("TestKey", HKEY_CURRENT_USER);
  Name = Key.Name;
  // Determines how many keys the current key contains
  Count = Key.SectionCount;

  if (Count > 0)
    {
    Log.AppendFolder("The " + Name + " registry key contains the following subkeys:");
    // Iterates through the keys
    for (var i = 0; i < Count; i++)
      {
      // Gets the name of the key by its index
      SubKeyName = Key.GetSectionName(i);
      // Posts the name to the test log
      Log.Message(SubKeyName);
      }
    Log.PopLogFolder();
    }

}

Python

def Test():
  # Gets an object for the Windows system registry key
  Key = Storages.Registry("TestKey", HKEY_CURRENT_USER)
  Name = Key.Name
  # Determines how many keys the current key contains
  Count = Key.SectionCount

  if (Count > 0):
    Log.AppendFolder("The " + Name + " registry key contains the following subkeys:")
    # Iterates through the keys
    for i in range (0, Count):
      # Gets the name of the key by its index
      SubKeyName = Key.GetSectionName(i)
      # Posts the name to the test log
      Log.Message(SubKeyName)
    Log.PopLogFolder()

VBScript

Sub Test

  Dim Key, Name, SubKeyName, Count
  ' Gets an object for the Windows system registry key
  Set Key = Storages.Registry("TestKey", HKEY_CURRENT_USER)
  Name = Key.Name
  ' Determines how many keys the current key contains
  Count = Key.SectionCount

  If Count > 0 Then
    Log.AppendFolder("The " & Name & " registry key contains the following subkeys:")
    ' Iterates through the keys
    For i = 0 To Count - 1

      ' Gets the name of the key by its index
      SubKeyName = Key.GetSectionName(i)
      ' Posts the name to the test log
      Log.Message(SubKeyName)

    Next
    Log.PopLogFolder
  End If

End Sub

DelphiScript

procedure Test();
var Key, Name, SubKeyName, Count, i;
begin
  // Gets an object for the Windows system registry key
  Key := Storages.Registry('TestKey', HKEY_CURRENT_USER);
  Name := Key.Name;
  // Determines how many keys the current key contains
  Count := Key.SectionCount;

  if Count > 0 then
    begin
    Log.AppendFolder('The ' + Name + ' registry key contains the following subkeys:');
    // Iterates through the keys
    for i := 0 to Count - 1 do
      begin
      // Gets the name of the key by its index
      SubKeyName := Key.GetSectionName(i);
      // Posts the name to the test log
      Log.Message(SubKeyName);
      end;
    Log.PopLogFolder();
    end;

end;

C++Script, C#Script

function Test()
{
  var Key, Name, SubKeyName, Count;
  // Gets an object for the Windows system registry key
  Key = Storages["Registry"]("TestKey", HKEY_CURRENT_USER);
  Name = Key["Name"];
  // Determines how many keys the current key contains
  Count = Key["SectionCount"];

  if (Count > 0)
    {
    Log["AppendFolder"]("The " + Name + " registry key contains the following subkeys:");
    // Iterates through the keys
    for (var i = 0; i < Count; i++)
      {
      // Gets the name of the key by its index
      SubKeyName = Key["GetSectionName"](i);
      // Posts the name to the test log
      Log["Message"](SubKeyName);
      }
    Log["PopLogFolder"]();
    }

}

See Also

GetOptionName Method
GetSectionNames Method
GetSubSectionByIndex Method
SectionCount Property

Highlight search results