paCfgReadValue()

The function reads the value of a specified entry in a config file section. If there are several identical values, only the last one will be read.

Synopsis

int paCfgReadValue([dyn_]string fileName, string section, string key, <type> &value[, string host])

int paCfgReadValue([dyn_]string fileName, string section, dyn_string &keys, dyn_<type> &values[, string host])

Parameters

Parameter Description
fileName

The file path of the config file or multiple files, for example getPath(CONFIG_REL_PATH, "config").

Note: The entire path of the config file must be specified.
section Section of the config file, for example, "general"
key/keys The config entry/entries whose value(s) will be read, for example, "langs"
value(s) The value(s) that is/are read.
host If this parameter has been specified, only the entries with this host, for example, $host1 will be read. If the host is empty "", only entries without a host name will be read. If no host parameter has been specified, no host entries will be read.

Return Value

In case of errors the function returns -1 and otherwise 0.

Example

Note: Note that you have to include the CtrlPv2Admin DLL into the general part of the code (so that you can use the paCfgInsertValue function) as follows: #uses "CtrlPv2Admin"

The following example reads the value of the lang entry from the general section of the config file.

main()
{
  string lang;
  int rc = paCfgReadValue(getPath(CONFIG_REL_PATH, "config"), "general", "lang", lang);

  if (rc == -1)
  {
     dyn_errClass lastError = getLastError();
     DebugTN("lastError", lastError);
  }
  DebugN("rc", rc, "lang", lang);
}
Note: Note that the maximum number of characters in a line of the configuration file is restricted to 511 characters (see also Configuration file). If this number is exceeded, -1 is returned.

Example

The following example reads the values of the LoadCtrlLibs entry from the ascii section of the config.level file.

main()
{
  string val;
  string section = "ascii";
  int rc = paCfgReadValue(getPath(CONFIG_REL_PATH, "config"), section, "LoadCtrlLibs", val);
  /* reads the values of the LoadCtrlLibs entry from the ascii section of the config.level file */
  if (rc == -1)
  {
     dyn_errClass lastError = getLastError();
     DebugTN("lastError", lastError);
  }
  DebugN("rc", rc, "val", val);
}         

Assignment

Project administration functions

Availability

CTRL