GetOptionName Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use this method to get the name of an option in the current section. The sought-for option is identified by its index in the option collection of the current section. The index starts from 0. To get the number of options in this collection, use the OptionCount property. To get the value of the option by its index, use the GetOptionByIndex method.

If the specified option does not exist, the GetOptionName method will create it.

Declaration

ProgObj.GetOptionName(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 option. The index is zero-based, that is, the first option has index 0, the second - 1, and so on. Index of the last option is OptionCount-1.

Result Value

The name of the specified option.

Example

The following code snippet determines how many values the registry key contains. After that, it iterates through the values and posts them to the test log.

JavaScript, JScript

function Test()
{

  var Key, Name, Count, ValueName, Value;

  // Gets an object for the Windows system registry key
  Key = Storages.Registry("TestKey\\Subkey", HKEY_CURRENT_USER, AQRT_32_BIT, true);
  Name = Key.Name;

  // Determines how many values the key contains
  Count = Key.OptionCount;
  if (Count > 0)
    {
    Log.AppendFolder("The" + Name + " registry key contains the following values:");

    // Iterates through the values
    for (var i = 0; i < Count; i++)
      {
      // Obtains the name of the value
      ValueName = Key.GetOptionName(i);
      // Obtains the value
      Value = Key.GetOption(ValueName, "not specified");
      // Posts the value to the test log
      Log.Message(ValueName + ": " + Value);
      }
    Log.PopLogFolder();
    }

}

Python

def Test():

  # Gets an object for the Windows system registry key
  Key = Storages.Registry("TestKey\\Subkey", HKEY_CURRENT_USER, AQRT_32_BIT, True)
  Name = Key.Name

  # Determines how many values the key contains
  Count = Key.OptionCount
  if (Count > 0):
    Log.AppendFolder("The" + Name + " registry key contains the following values:")

    # Iterates through the values
    for i in range (0, Count):
      # Obtains the name of the value
      ValueName = Key.GetOptionName(i)
      # Obtains the value
      Value = Key.GetOption(ValueName, "not specified")
      # Posts the value to the test log
      Log.Message(ValueName + ": " + str(Value))
    Log.PopLogFolder()

VBScript

Sub Test

  Dim Key, Name, Count, ValueName, Value

  ' Gets an object for the Windows system registry key
  Set Key = Storages.Registry("TestKey\Subkey", HKEY_CURRENT_USER, AQRT_32_BIT, True)
  Name = Key.Name

  ' Determines how many values the key contains
  Count = Key.OptionCount
  If Count > 0 Then
    Log.AppendFolder("The" & Name & " registry key contains the following values:")

    ' Iterates through the values
    For i = 0 To Count - 1
      ' Obtains the name of the value
      ValueName = Key.GetOptionName(i)
      ' Obtains the value
      Value = Key.GetOption(ValueName, "not specified")
      ' Posts the value to the test log
      Log.Message(ValueName & ": " & Value)
    Next
    Log.PopLogFolder
  End If

End Sub

DelphiScript

procedure Test();
var Key, Name, Count, ValueName, Value, i;

begin

  // Gets an object for the Windows system registry key
  Key := Storages.Registry('TestKey\Subkey', HKEY_CURRENT_USER, AQRT_32_BIT, true);
  Name := Key.Name;

  // Determines how many values the key contains
  Count := Key.OptionCount;
  if Count > 0 then
    begin
    Log.AppendFolder('The' + Name + ' registry key contains the following values:');

    // Iterates through the values
    for i := 0 to Count - 1 do
      begin
      // Obtains the name of the value
      ValueName := Key.GetOptionName(i);
      // Obtains the value
      Value := Key.GetOption(ValueName, 'not specified');
      // Posts the value to the test log
      Log.Message(ValueName + ': ' + aqConvert.VarToStr(Value));
      end;
    Log.PopLogFolder;
    end;

end;

C++Script, C#Script

function Test()
{

  var Key, Name, Count, ValueName, Value;

  // Gets an object for a Windows system registry key
  Key = Storages["Registry"]("TestKey\\Subkey", HKEY_CURRENT_USER, AQRT_32_BIT, true);
  Name = Key["Name"];

  // Determines how many values the key contains
  Count = Key["OptionCount"];
  if (Count > 0)
    {
    Log["AppendFolder"]("The" + Name + " registry key contains the following values:");

    // Iterates through the values
    for (var i = 0; i < Count; i++)
      {
      // Obtains the name of the value
      ValueName = Key["GetOptionName"](i);
      // Obtains the value
      Value = Key["GetOption"](ValueName, "not specified");
      // Posts the value to the test log
      Log["Message"](ValueName + ": " + Value);
      }
    Log["PopLogFolder"]();
    }

}

See Also

GetOptionByIndex Method
GetOptionNames Method
GetSectionName Method
OptionCount Property

Highlight search results