The PropertiesFile4Delphi consists of a library for handling key=value format configuration files.
Many times, for various reasons, it is necessary to parameterize the application starting from a configuration mechanism. In Delphi is common to use INI files to store the settings, but working with these files is a bit repetitive and unproductive. The API PropertiesFile4Delphi facilitates this work with configuration files replacing the use of INI files. It is an API to manage simple text files, which are written with the key=value syntax, storing a unique key per line.
- Store and load data via simplified interface;
- Map configuration files to simplified classes.
- Delphi Community Edition - The IDE used
To get a local copy up and running follow these simple steps.
To use this library an updated version of Delphi IDE (XE or higher) is required.
Clone the repo
git clone https://github.com/ezequieljuliano/PropertiesFile4Delphi.git
Add the "Search Path" of your IDE or your project the following directories:
PropertiesFile4Delphi\src
Create or edit configuration files by declaring a variable of type IPropertiesFile and using the TPropertiesFileStorage implementation:
uses
PropertiesFile,
PropertiesFile.Storage;
procedure Save;
var
propertiesFile: IPropertiesFile;
begin
propertiesFile := TPropertiesFileStorage.Create;
propertiesFile.PropertyItem['app.title'] := 'Properties File For Delphi';
propertiesFile.PropertyItem['app.version'] := '1.0.0';
propertiesFile.SaveToFile('application.properties');
end;
uses
PropertiesFile,
PropertiesFile.Storage;
procedure Load;
var
propertiesFile: IPropertiesFile;
begin
propertiesFile := TPropertiesFileStorage.Create;
propertiesFile.LoadFromFile('application.properties');
Self.Caption := propertiesFile.PropertyItem['app.title'] + '-' + propertiesFile.PropertyItem['app.version'];
end;
PropertiesFile4Delphi library provides a set of mapping classes. This way you can work directly with classes rather than getting manipulating files in your source code. The first step to using the configuration mechanism in an application is to create a specific class to store the desired parameters and write it down with [PropertiesFile] and inherit TPropertiesFileObject class.
Mapping example:
uses
PropertiesFile.Mapping;
type
[PropertiesFile('security.properties')]
TSecurityConfig = class(TPropertiesFileObject)
private
[NotNull]
[PropertyItem('username')]
fUsername: string;
[NotNull]
[PropertyItem('password')]
fPassword: string;
public
property Username: string read fUsername write fUsername;
property Password: string read fPassword write fPassword;
end;
When the class is destroyed the file is automatically saved:
procedure Load;
var
securityConfig: TSecurityConfig;
begin
securityConfig := TSecurityConfig.Create;
try
securityConfig.Username := 'admin';
securityConfig.Password := 'admin';
finally
securityConfig.Free;
end;
end;
When instantiating the class the data is loaded:
procedure Login;
var
securityConfig: TSecurityConfig;
begin
securityConfig := TSecurityConfig.Create;
try
Login(securityConfig.Username, securityConfig.Password);
finally
securityConfig.Free;
end;
end;
Supported field mappings:
- PropertyItem: alias field definition;
- NotNull: mandatory field definition;
- Ignore: Fields that should be ignored;
- ReadOnly: Fields that are read-only (can be applied at class level).
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the APACHE LICENSE. See LICENSE
for more information.
To contact us use the options:
- E-mail : [email protected]
- Twitter : @ezequieljuliano
- Linkedin: ezequiel-juliano-müller