|
Software Development Kit to the Delphi-Win32 and Free Pascal compilers |
| Home > Wiki > Configuration file |
Configuration fileenglish (en) | português (br) A PressObjects application (POA) can have a configuration file that provides the application with information and settings for its services at run time. The configuration file can contain settings for the published properties of services. As an example, for persistence brokers, it can provide settings such as database path, user name and password.
[edit] File nameThe default configuration file name is derived from the POA's name by changing its file extension to the value of the SPressConfigFileExt constant. To use a different configuration file name, set it as the value for the PressApp.ConfigFileName property in the initialization section of any unit. [edit] File locationA POA checks for the existence of a configuration file in the same folder as its executable file. [edit] File Read TimingA configuration file is loaded during the POA's initialization, just before the application starts running but after the initialization section of all units. [edit] Initialization of service settingsThe service property settings are updated to the values in the configuration file when a service instance is required for the first time. [edit] File formatThe format of the configuration file is similar to an 'INI' file. It is divided into sections, each started with a header enclosed in square brackets. A header consists of a service type name and optionally a service sub-type name separated by a period(.). Each section can contain items, each of which correspond to a published property of the related service. Comments can be included by preceding them with '#' or '//'. Any entries after these on a line are ignored. An example for the Phonebook.exe demo application follows: in file "PhoneBook.cf" [OPFBroker] // Tell the OPFBroker service to use the IBX broker DefaultServiceName := 'IBX'; #DefaultServiceName := 'SQLdb'; [OPFBroker.SQLdb] // These settings are not used Connector.Database.ConnectorType := 'firebird'; Connector.Database.DatabaseName := 'localhost:G:\Database\IBX\PO\Phonebook.fb'; Connector.Database.UserName := 'sysdba'; Connector.Database.Password := 'masterkey'; [OPFBroker.IBX] // Include the required settings for the IBX broker Connector.Database.DatabaseName := 'localhost:G:\Database\IBX\PO\Phonebook.gdb'; Connector.UserName := 'sysdba'; Connector.Password := 'masterkey'; [edit] User defined functionsThe user can create functions that is recognized by the configuration file parser, eg, to decrypt a password. [edit] Declaration
interface
uses
PressConfig;
type
TDecryptFnc = class(TPressConfigFunction)
protected
function GetValue: string; override;
end;
implementation
function TDecryptFnc.GetValue: string;
begin
// Params.Count has the number of params
// Params[n] has the n param (zero based) as string
// Assign the function's result value to the Result var
end;
initialization
TDecryptFnc.RegisterFunction('Decrypt');
IOW create a TPressConfigFunction descendant (from the PressConfig unit), overrides the GetValue function and register the class using its RegisterFunction class method providing the name of the function in the first parameter. [edit] Usagewithin the config file Connector.Password := Decrypt(twofish, 'aabb'); [edit] ImplementationThe config file doesn't parse the arguments, so Params[0] has the string 'twofish' and Params[1] has a quoted 'aabb' string. The function PressUnquotedStr (unit PressUtils) removes the quotes of string values. The result is also a string value. If the property expects an integer or an enumeration, translate it to its string representation:
|
Personal tools |