Storages.INI Method

Applies to TestComplete 14.50, last modified on April 22, 2021

Description

Use the Storages.INI method to open an INI file to read values from or write values to it.

The INI file must have the [Root] section, otherwise, the method will be unable to open the file. This section can be empty, or it can hold values like any other section.

If the specified INI file does not exist, Storages.INI creates it in memory. You can save the created file to the disk later by calling the Save or SaveAs method of the returned FileSection object.

Declaration

Storages.INI(FileName)

FileName [in]    Required    String    
Result A FileSection object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

FileName

The fully-qualified name of the INI file to open or create.

Result Value

The FileSection object that corresponds to the [Root] section of the specified INI file. To access the other sections, use the GetSubSection or GetSubSectionByIndex method of the returned object.

If the INI file does not have the required [Root] section, or the file is not a valid INI file, an error will occur.

Example

The example below demonstrates how you can read values from an INI file.

MyFile.ini

; IMPORTANT: The Root section is required
[Root]

[Settings]
Access=ReadWrite
Type=1

[Temp]
Mask=*.log

JavaScript, JScript

function Test()
{

  var ini = Storages.INI("C:\\MyFile.ini");

  // Reads the Type value from the Settings section
  var value = ini.GetSubSection("Settings").GetOption("Type", 0);
  Log.Message(value);

  // Reads the Mask value from the Temp section
  value = ini.GetSubSection("Temp").GetOption("Mask", "");
  Log.Message(value);
}

Python

def Test():
  
  ini = Storages.INI("C:\MyFile.ini")

  # Reads the Type value from the Settings section 
  value = ini.GetSubSection("Settings").GetOption("Type", 0)
  Log.Message(value)

  # Reads the Mask value from the Temp section 
  value = ini.GetSubSection("Temp").GetOption("Mask", "")
  Log.Message(value)

VBScript

Sub Test
  Dim ini, value

  Set ini = Storages.INI("C:\MyFile.ini")

  ' Reads the Type value from the Settings section
  value = ini.GetSubSection("Settings").GetOption("Type", 0)
  Log.Message value

  ' Reads the Mask value from the Temp section
  value = ini.GetSubSection("Temp").GetOption("Mask", "")
  Log.Message value
End Sub

DelphiScript

procedure Test;
var ini, value;
begin

  ini := Storages.INI('C:\MyFile.ini');

  // Reads the Type value from the Settings section
  value := ini.GetSubSection('Settings').GetOption('Type', 0);
  Log.Message(value);

  // Reads the Mask value from the Temp section;
  value := ini.GetSubSection('Temp').GetOption('Mask', '');
  Log.Message(value);
end;

C++Script, C#Script

function Test()
{

  var ini = Storages["INI"]("C:\\MyFile.ini");

  // Reads the Type value from the Settings section
  var value = ini["GetSubSection"]("Settings")["GetOption"]("Type", 0);
  Log["Message"](value);

  // Reads the Mask value from the Temp section
  value = ini["GetSubSection"]("Temp")["GetOption"]("Mask", "");
  Log["Message"](value);
}

For an example of writing a value to an INI file, see Writing Sections and Options to an INI File. Example.

See Also

Writing Sections and Options to an INI File. Example
FileSection Object
Binary Method
Registry Method
XML Method

Highlight search results