3.4.1. Connection Parameters in a Configuration File

Since the connection parameters, except for the username and password and possibly the role, are usually common to all instances the application, we will read them from the configuration file:

  1. xIniFile := TIniFile.Create(xAppPath + 'config.ini');
  2. try
  3. xIniFile.ReadSectionValues('connection', FDConnection.Params);
  4. finally
  5. xIniFile.Free;
  6. end;

A Typical Configuration File

Typically, the config.ini file contains the following lines:

  1. [connection]
  2. DriverID=FB
  3. Protocol=TCPIP
  4. Server=localhost/3051
  5. Database=examples
  6. OSAuthent=No
  7. RoleName=
  8. CharacterSet=UTF8

You can get the contents of the connection section by copying the contents of the Params property of the TFDConnection component after the wizard finishes its work.

Actually, the common settings are usually located in %AppData%\Manufacturer\AppName and are saved to that location by the application installation software. However, it is convenient for the configuration file to be stored somewhere closer during the development, for instance, in the application folder.

Note that if your application is installed into the Program Files folder and the configuration file is located there as well, it is likely that the file will be virtualized in Program Data and issues could arise with modifying it and reading the new settings subsequently.