2005-08-26 10:25:39 +00:00
|
|
|
{
|
|
|
|
:: X2UtConfig provides a generic access mechanism for application settings.
|
|
|
|
:: Create an instance of one of the TX2xxxConfigSource classes (such as
|
|
|
|
:: TX2IniConfigSource in the X2UtConfigIni.pas unit) to gain access to an
|
|
|
|
:: IX2ConfigSource interface.
|
|
|
|
::
|
|
|
|
:: Though no actual code was ported, credits to Nini for .NET
|
|
|
|
:: (http://nini.sourceforge.net/) for some excellent ideas. In fact,
|
|
|
|
:: X2UtXMLConfigSource is capable of recognizing, reading and writing
|
|
|
|
:: Nini-compatible XML files.
|
|
|
|
::
|
2005-10-18 09:25:05 +00:00
|
|
|
:: To accomodate for tree structures, configuration names may contain a
|
|
|
|
:: dot (.) to separate the sections. While they are used as-is in flat
|
|
|
|
:: sources (INI), they are used for subkeys in tree source (Registry, XML).
|
|
|
|
:: The SectionSeparator variable is available for this purpose.
|
|
|
|
::
|
2005-08-26 10:25:39 +00:00
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
|
|
|
:: Author: $Author$
|
|
|
|
}
|
|
|
|
unit X2UtConfig;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
X2UtHashes;
|
2005-08-26 10:25:39 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
// Forward declarations
|
2005-10-18 09:25:05 +00:00
|
|
|
IX2ConfigSource = interface;
|
|
|
|
IX2Config = interface;
|
|
|
|
IX2ConfigDefinition = interface;
|
|
|
|
IX2ConfigDefinitionObserver = interface;
|
2005-08-26 10:25:39 +00:00
|
|
|
|
|
|
|
{
|
2005-10-18 09:25:05 +00:00
|
|
|
:$ Callback method for config iteration
|
2005-08-26 10:25:39 +00:00
|
|
|
}
|
2005-10-18 09:25:05 +00:00
|
|
|
TX2ConfigIterateConfigs = procedure(Sender: IX2ConfigSource;
|
|
|
|
const Name: String;
|
|
|
|
const Data: Pointer) of object;
|
2005-08-26 10:25:39 +00:00
|
|
|
|
|
|
|
{
|
2005-10-18 09:25:05 +00:00
|
|
|
:$ Callback method for value iteration
|
2005-08-26 10:25:39 +00:00
|
|
|
}
|
2005-10-18 09:25:05 +00:00
|
|
|
TX2ConfigIterateValues = procedure(Sender: IX2Config;
|
|
|
|
const Name: String;
|
|
|
|
const Data: Pointer) of object;
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
{
|
|
|
|
:$ Determines which values should be cleared.
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
:: caAll clears all values
|
|
|
|
:: caDefined clears only values which have been defined using
|
|
|
|
:: IX2ConfigSource.Register
|
|
|
|
:: caUndefined clears only values which have not been defined using
|
|
|
|
:: IX2ConfigSource.Register
|
|
|
|
}
|
|
|
|
TX2ConfigClearAction = (caAll, caDefined, caUndefined);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
:$ Interface for configuration sources.
|
|
|
|
}
|
|
|
|
IX2ConfigSource = interface
|
|
|
|
['{1FF5282B-122F-47D7-95E8-3DB60A8CF765}']
|
|
|
|
function GetAutoSave(): Boolean;
|
|
|
|
procedure SetAutoSave(Value: Boolean);
|
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
procedure Reload();
|
|
|
|
procedure Save(); overload;
|
|
|
|
procedure Save(const AStream: TStream); overload;
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
function Configs(const AName: String): IX2Config;
|
2005-08-26 10:25:39 +00:00
|
|
|
function Exists(const AName: String): Boolean;
|
2005-10-18 09:25:05 +00:00
|
|
|
|
2005-08-26 10:25:39 +00:00
|
|
|
procedure Delete(const AName: String);
|
2005-10-18 09:25:05 +00:00
|
|
|
procedure Clear(const AAction: TX2ConfigClearAction);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
procedure Iterate(const ACallback: TX2ConfigIterateConfigs;
|
|
|
|
const AData: Pointer);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
function Register(const AConfig, AName: String): IX2ConfigDefinition; overload;
|
|
|
|
function Register(const AConfig, AName: String;
|
|
|
|
const ADefault: Variant): IX2ConfigDefinition; overload;
|
|
|
|
function Definitions(const AConfig, AName: String): IX2ConfigDefinition;
|
2005-08-26 10:25:39 +00:00
|
|
|
|
|
|
|
property AutoSave: Boolean read GetAutoSave write SetAutoSave;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
2005-10-18 09:25:05 +00:00
|
|
|
:$ Interface for configurations.
|
2005-08-26 10:25:39 +00:00
|
|
|
}
|
2005-10-18 09:25:05 +00:00
|
|
|
IX2Config = interface
|
|
|
|
['{25DF95C1-CE09-44A7-816B-A33B8D0D78DC}']
|
2005-08-26 10:25:39 +00:00
|
|
|
function GetName(): String;
|
2005-10-18 09:25:05 +00:00
|
|
|
function GetSource(): IX2ConfigSource;
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
function Exists(const AName: String): Boolean;
|
|
|
|
function Read(const AName: String): Variant; overload;
|
|
|
|
function Read(const AName: String; const ADefault: Variant): Variant; overload;
|
|
|
|
procedure Write(const AName: String; const AValue: Variant);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
|
|
|
procedure Delete(const AName: String);
|
2005-10-18 09:25:05 +00:00
|
|
|
procedure Clear(const AAction: TX2ConfigClearAction);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
procedure Iterate(const ACallback: TX2ConfigIterateValues;
|
|
|
|
const AData: Pointer);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
property Name: String read GetName;
|
|
|
|
property Source: IX2ConfigSource read GetSource;
|
2005-08-26 10:25:39 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
2005-10-18 09:25:05 +00:00
|
|
|
:$ Interface for configuration value definitions.
|
2005-08-26 10:25:39 +00:00
|
|
|
}
|
2005-10-18 09:25:05 +00:00
|
|
|
IX2ConfigDefinition = interface
|
|
|
|
['{00C67656-24FB-4CBE-81DC-B064A5550820}']
|
|
|
|
function GetDefault(): Variant;
|
|
|
|
function GetConfig(): String;
|
|
|
|
function GetName(): String;
|
|
|
|
procedure SetDefault(Value: Variant);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
procedure Attach(const AObserver: IX2ConfigDefinitionObserver);
|
|
|
|
procedure Detach(const AObserver: IX2ConfigDefinitionObserver);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
procedure Read(var AValue: Variant);
|
|
|
|
procedure Write(var AValue: Variant);
|
2005-08-26 10:25:39 +00:00
|
|
|
|
2005-10-18 09:25:05 +00:00
|
|
|
property Default: Variant read GetDefault write SetDefault;
|
|
|
|
property Config: String read GetConfig;
|
|
|
|
property Name: String read GetName;
|
2005-08-26 10:25:39 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
2005-10-18 09:25:05 +00:00
|
|
|
:$ Interface for configuration value definition observers.
|
2005-08-26 10:25:39 +00:00
|
|
|
}
|
2005-10-18 09:25:05 +00:00
|
|
|
IX2ConfigDefinitionObserver = interface
|
|
|
|
['{EE20E59D-6642-42D7-A520-6A4F1C5FD3EA}']
|
|
|
|
procedure Read(const AConfig, AName: String; var AValue: Variant);
|
|
|
|
procedure Write(const AConfig, AName: String; var AValue: Variant);
|
2005-08-26 10:25:39 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
SectionSeparator: Char = '.';
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
end.
|