unit singleton.config;
{$mode ObjFPC}{$H+}
{$m+}
{$TYPEDADDRESS ON}
interface
uses
Classes, SysUtils, StrUtils,
Token, PathsHandler;
type
{TConfig}
PConfig = ^TConfig;
TConfig = class
private
FDayLongStartTime : shortstring;
FDayLongEndTime : shortstring;
FDayLongMinBpm : Byte;
FDayLongMaxBpm : Byte;
FDayLongPath : string;
FNightLongStartTime : shortstring;
FNightLongEndTime : shortstring;
FNightLongMinBpm : Byte;
FNightLongMaxBpm : Byte;
FNightLongPath : string;
FFileType : shortstring;
FLastDirectionOfSort : shortstring;
FDayLongParams : shortstring;
FNightLongParams : shortstring;
FBasePath : string;
FMinBpm : Byte;
FMaxBpm : Byte;
FLastPeriod : shortstring;
FNameOfIndex : shortstring;
FConfigFile : string;
FDelimiter : Char;
FCurrentDir : string;
FCurrentPeriod : shortstring;
FListOfSort : TStringList;
FListOfImport : TStringList;
protected
procedure DoRun;
public
constructor Create(TheOwner: TComponent; Cf: string; Dl: Char);
destructor Destroy;
property DayLongStartTime : shortstring read FDayLongStartTime write FDayLongStartTime;
property DayLongEndTime : shortstring read FDayLongEndTime write FDayLongEndTime;
property DayLongMinBpm : Byte read FDayLongMinBpm write FDayLongMinBpm;
property DayLongMaxBpm : Byte read FDayLongMaxBpm write FDayLongMaxBpm;
property DayLongPath : string read FDayLongPath write FDayLongPath;
property NightLongStartTime : shortstring read FNightLongStartTime write FNightLongStartTime;
property NightLongEndTime : shortstring read FNightLongEndTime write FNightLongEndTime;
property NightLongMinBpm : Byte read FNightLongMinBpm write FNightLongMinBpm;
property NightLongMaxBpm : Byte read FNightLongMaxBpm write FNightLongMaxBpm;
property NightLongPath : string read FNightLongPath write FNightLongPath;
property FileType : shortstring read FFileType write FFileType;
property LastDirectionOfSort : shortstring read FLastDirectionOfSort write FLastDirectionOfSort;
property DayLongParams : shortstring read FDayLongParams write FDayLongParams;
property NightLongParams : shortstring read FNightLongParams write FNightLongParams;
property BasePath : string read FBasePath write FBasePath;
property MinBpm : Byte read FMinBpm;
property MaxBpm : Byte read FMaxBpm;
property LastPeriod : shortstring read FLastPeriod write FLastPeriod;
property NameOfIndex: shortstring read FNameOfIndex write FNameOfIndex;
property ConfigFile: string read FConfigFile write FConfigFile;
property Delimiter: Char read FDelimiter write FDelimiter;
property CurrentDir: string read FCurrentDir write FCurrentDir;
property CurrentPeriod: shortstring read FCurrentPeriod;
property ListOfSort: TStringList read FListOfSort write FListOfSort;
procedure WriteConfig(Prop: shortstring; Val: string);
function ReadConfig(Req: shortstring): string;
function TrimLeadingZeros(const S: string): string;
function StrToMinutes(S: string): Integer;
end;
{ Singleton-function provides access to 1 TConfig instance, you need only call
it once with parameters, after that just call it without 'cause they're all default }
function gConfig(TheOwner: TComponent = nil; Cf: string = ''; Dl: Char = ' '): TConfig;
implementation
var Singleton: TConfig = nil;
function gConfig(TheOwner: TComponent = nil; Cf: string = ''; Dl: Char = ' '): TConfig;
begin
if not Assigned(Singleton) then Singleton:= TConfig.Create(TheOwner,Cf,Dl);
Result:= Singleton;
end;
finalization
if Assigned(Singleton) then Singleton.Free;
end.