Promotic
WikipediaLinkedInYoutubeTwitterFacebook

XML and INI configuration files structure description for $.cfgfile macro expression

The configuration files are used for saving constants (parameters and initial values) of the application. Sometimes it is handy not to enter some constants directly into the PROMOTIC application (i.e. into the "Application.pra" file), but to save it into the configuration (text) file that are linked from the PROMOTIC application. This allows to change the application parameters in this file without the need to edit the application itself. The Promotic configuration files are text files in the XML format (newer) or INI (original, older). Macro expression $.cfgfile is the easiest and basic way, of obtaining the values contained in the the configuration files (both INI and XML).

The XML configuration file allows to save the values into arbitrary hierarchical level. Macro expression $.cfgfile enables access to values in any hierarchical level. INI configuration file contains just two levels (section/key).

 

1. XML (*.xml) configuration files for $.cfgfile

XML text file consists of tags, atributes and values. XML allows to enter structured (hierarchical) entiries of values. The tags are always paired, marking the beginning ant the end of current section. XML file can be displayed in any internet browser (e.g. Internet Explorer), that also checks the correctness of the syntax.

For alternative (but very general) access to values in XML files, see How to read common XML files in the application.

Example:
Example of the config.xml file with the following content:
<?xml version="1.0" encoding="utf-8"?>
<root>
  <data>
    <ipaddress>192.168.1.2</ipaddress>
    <pcname>ctest</pcname>
    <webportnumber>81</webportnumber>
  </data>
</root>
An example of link to value webportnumber in <data> tag supposing that the file config.xml is registered in the Manager of configuration files configurator identified as config:
$.cfgfile("config/data/webportnumber",80)

2. INI (*.ini) configuration files for $.cfgfile

INI text file of the OS Windows consists of sections and keys - see Description of the *.ini file structure.
 
The alternative access to INI file values can be managed by Pm.IniFileRead and Pm.IniFileWrite methods.
Example1:
Example of the config.ini file with the following content:
[data]
ipaddress=192.168.1.2
pcname=ctest
webportnumber=81
Example2:
An example of link to a key value webportnumber in [data] section supposing that the file config.ini is registered in the Manager of configuration files configurator identified as config:
$.cfgfile("config/data/webportnumber",80)
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice