Addressing Initialization and Assignment Settings with $setting

You can use $setting to add or change the value of an initialization or assignment setting, and to retrieve lists of settings or file sections. It is not possible to add file sections.

Add or change a setting:

$setting (ConfigFile, Section\Setting, "INIDATA") = Value

$setting ("C:\my_app.ini", "upi\msglines", "INIDATA") = 5 

Retrieve settings:

ReturnedValue = $setting(ConfigFile, RetrieveProfile, "INISECTIONS | INISETTINGS | INIDATA")

vSections = $setting ("C:\my_app.ini", "u*", "INISECTIONS") 
vSettings = $setting ("", "upi\*", "INISETTINGS")
vValue = $setting ("", "upi\msglines", "INIDATA")

Parameters

Parameters

Parameter

Data Type

Description

ConfigFile

String

Location of the setting or settings. Valid values are:

  • Empty string ("")—the .ini file specified by /ini , or the default usys.ini
  • IniFile—name of an initialization file.
  • AsnFile—name of an assignment file. The name must end with the .asn extension.

RetrieveProfile

String

Profile to retrieve the desired sections or settings. The profile must match the Topic. To retrieve multiple sections or settings, you can use the GOLD * and GOLD ? characters.

Section\Setting

String

Initialization or assignment setting whose value you want to retrieve or set. Maximum length for each segment (Section and Setting) is 512 characters.

INIDATA

String

Set or get the value of a setting in ConfigFile. Wildcards are not allowed, and the RetrieveProfile or setting specification must include the field section in which the setting is located.

INISETTINGS

String

Get a list of settings within the specified section. Wildcards can be used for Setting, but not for Section. For example:

vSettings = $setting ("", "upi\*", "INISETTINGS")

INISECTIONS

String

Get a list of file sections in ConfigFile. Wildcards can be used. For example:

vSections = $setting ("C:\my_app.ini", "u*", "INISECTIONS")
Value String Value to add or change in the file for the specified setting; maximum 1023 characters when Topic is INIDATA.

Syntax of RetrieveProfile and Setting

The second parameter of $settings can specify a retrieve profile or a specific setting. You can use the following syntax:

Section\Setting

If Topic is INISETTINGS and INIDATA, the Section must be explicitly defined. If Setting is empty, an error is returned if Topic is INISETTINGS or INIDATA.

If Topic is INISECTIONS, specifying Setting returns an error.

Effect of Topic on Second Parameter

The way Uniface interprets the second parameter depends on the value of the Topic parameter.

  • When Topic is INIDATA, the second parameter is always interpreted as a specific setting and it cannot contain wildcards (GOLD * and GOLD ?) . The setting specification must include the file section. For example:
    ; set the value of the translines setting 
    $setting("usys.ini","upi\translines", "INIDATA") = 5000
    
    ; retrieve the value of Uniface's javascript path:
    vSetting = $setting("usys.ini","paths\javascript", "INIDATA")
  • When Topic is INISETTINGS or INISECTIONS, the second parameter is interpreted as a retrieve profile, so it can contain wildcards (GOLD * and GOLD ?). For example:
    ;retrieve vSections = $setting("","*","INISECTIONS")
    vSettings = $setting("usys.ini","paths\*", "INISETTINGS")
     

    Note: When using INISETTINGS, it is not possible to use wildcards in both the Section and Setting part of the second parameter. To retrieve a list of all initialization or assignment settings in a source, you need to first get a list of all the file sections, and then loop through that list to get a list of the settings in each section. See Retrieve a List of All Settings in a Source.

  • When Topic is INIDATA, if the specified Section, Setting, or Value is larger than the maximum length, error -1118 is returned.

Adding or Changing a Setting

You can add or modify a setting only if Topic is INIDATA. If the setting does not exist, it is added to the end of the section. If the setting already exists, the value is changed.

To set the value, put the $setting function on the left side of an assignment.

Note:  It is not possible to add a section to an initialization or assignment file using $setting.

Using $setting with Initialization Files

On Windows, the global (and default) initialization file is usys.ini. You can specify the ConfigFile as an empty string (so usys.ini is used) or as a specific initialization file. On other platforms, initialization files are user-defined.

When retrieving multiple sections or sections, use a retrieve profile (GOLD *).

For example:

  • To retrieve a list of sections starting with U from an my_app.ini file:
    vSections = $setting ("C:\my_app.ini", "u*", "INISECTIONS") 
  • To retrieve a list of settings within a section of usys.ini:
    vSettings = $setting ("", "upi\*", "INISETTINGS")
  • Retrieve the value of a specific setting in usys.ini:
    vValue = $setting ("", "upi\msglines", "INIDATA")
    ;vValue = $setting ("", "[upi]msglines", "INIDATA") ;alternative Setting syntax
  • To modify or add a specific setting to the my_app.ini file:
    $setting ("C:\my_app.ini", "upi\msglines", "INIDATA") = 5 

Using $setting with Assignment Files

Uniface assignment files have the same format as initialization files, so it is possible to manipulate assignment settings and file sections as if they were initialization settings.

However, $settings behaves slightly differently for an assignment file than an initialization file:

  • It determines the assignment file semantics based on the file name (it must end in .asn) and the section name (it must be a valid section file name).
  • For Uniface assignment files, settings in the [SETTINGS] and [PROXY_SETTINGS] sections can be specified with or without underscores.
  • A setting that does not take a value, returns the string value "True". In initialization files, such a setting returns an empty string "".

Retrieve a List of All Settings in a Source

The following example retrieves a list of all settings in the default usys.ini file.

variables
  string vSections, vSection,  vItemId1, vItemId2, vSettings,  vResult
endvariables

vSections = $setting("","·*","INISECTIONS") Callout 1

forlist vItemId1 in vSections Callout 2
  vSection=$concat (vItemId1,"/·*") Callout 3
  vSettings=$setting("",vSection,"INISETTINGS") Callout 4
  forlist vItemId2 in vSettings Callout 5
    putitem vResult, -1, vItemId2  Callout 6
  endfor
endfor
  1. Retrieve the list of sections in the source file. Since no source is specified, the usys.ini is used.
  2. For each section in the returned list:
  3.   Construct the retrieve query for settings by concatenating the section name (section) with the GOLD * wildcard.
  4.   Retrieve the list of settings in the specified section.
  5. For each setting in the returned list:
  6.   Add the item to the results list.