Class TParamsFile

Unit

Declaration

type TParamsFile = class(TObject)

Description

TParamsFile work as an instance of a settings file. You can have more than one instance for more than 1 settings file.

Hierarchy

Overview

Methods

Protected function getParamsFileName(ACreateFolder: boolean = False): string;
Protected function getParamValue(key: string): TJSONValue;
Protected procedure setParamValue(key: string; Value: TJSONValue);
Public constructor Create; overload;
Public constructor Create(AFilePath: string); overload;
Public destructor Destroy; override;
Public procedure Save;
Public procedure Load;
Public procedure Cancel;
Public procedure Delete(const ClearMemoryToo: boolean = true);
Public procedure Clear;
Public function getValue(key: string; default: string = ''): string; overload;
Public function getValue(key: string; default: boolean = False): boolean; overload;
Public function getValue(key: string; default: cardinal = 0): cardinal; overload;
Public function getValue(key: string; default: integer = 0): integer; overload;
Public function getValue(key: string; default: single = 0): single; overload;
Public function getValue(key: string; default: TDateTime = 0): TDateTime; overload;
Public function getValue(key: string; default: TJSONValue = nil) : TJSONValue; overload;
Public procedure setValue(key, Value: string); overload;
Public procedure setValue(key: string; Value: boolean); overload;
Public procedure setValue(key: string; Value: cardinal); overload;
Public procedure setValue(key: string; Value: integer); overload;
Public procedure setValue(key: string; Value: single); overload;
Public procedure setValue(key: string; Value: TDateTime); overload;
Public procedure setValue(key: string; Value: TJSONValue); overload;
Public procedure setFolderName(AFolderName: string; AReload: boolean = true);
Public procedure setFilePath(AFilePath: string; AReload: boolean = true);
Public procedure InitDefaultFileNameV2(Const AEditor, ASoftware: string; AReload: boolean = true);
Public procedure MoveToFilePath(ANewFilePath: string; ASave: boolean = true; ACreateFolder: boolean = False);
Public function getFilePath: string;
Public function ToJSON: string;
Public function AsJSONObject(AClone: boolean = true): TJSONObject;
Public procedure Remove(key: string);
Public function HasChanged: boolean;
Public procedure BeginUpdate;
Public procedure EndUpdate(const AutoSaveChanges: boolean = true);

Properties

Public property onBeforeLoadEvent: TParamsLoadSaveEvent read FonBeforeLoadEvent write SetonBeforeLoadEvent;
Public property onBeforeLoadProc: TParamsLoadSaveProc read FonBeforeLoadProc write SetonBeforeLoadProc;
Public property onAfterLoadEvent: TParamsLoadSaveEvent read FonAfterLoadEvent write SetonAfterLoadEvent;
Public property onAfterLoadProc: TParamsLoadSaveProc read FonAfterLoadProc write SetonAfterLoadProc;
Public property onBeforeSaveEvent: TParamsLoadSaveEvent read FonBeforeSaveEvent write SetonBeforeSaveEvent;
Public property onBeforeSaveProc: TParamsLoadSaveProc read FonBeforeSaveProc write SetonBeforeSaveProc;
Public property onAfterSaveEvent: TParamsLoadSaveEvent read FonAfterSaveEvent write SetonAfterSaveEvent;
Public property onAfterSaveProc: TParamsLoadSaveProc read FonAfterSaveProc write SetonAfterSaveProc;
Public property onCryptEvent: TParamsCryptEvent read FonCryptEvent write SetonCryptEvent;
Public property onCryptProc: TParamsCryptProc read FonCryptProc write SetonCryptProc;
Public property onDecryptEvent: TParamsDecryptEvent read FonDecryptEvent write SetonDecryptEvent;
Public property onDecryptProc: TParamsDecryptProc read FonDecryptProc write SetonDecryptProc;
Public property PortableMode: boolean read FPortableMode write SetPortableMode;

Description

Methods

Protected function getParamsFileName(ACreateFolder: boolean = False): string;
 
Protected function getParamValue(key: string): TJSONValue;
 
Protected procedure setParamValue(key: string; Value: TJSONValue);
 
Public constructor Create; overload;

Class constructor wich just initialize private fields.

Public constructor Create(AFilePath: string); overload;

Class constructor wich loads the parameter file specified as parameter.

Parameters
AFilePath
Absolute file path to the parameter file (drive+folder+file name+extension)
Public destructor Destroy; override;

Instance destructor

Public procedure Save;

Save current parameters to actual parameter file

Public procedure Load;

Load parameters from actual parameter file

Public procedure Cancel;

Cancel current changes and reload previous saved values

Public procedure Delete(const ClearMemoryToo: boolean = true);

Delete the file where settings are stored.

WARNING !!! No rollback. Deleting the file can't be canceled.

Public procedure Clear;

Clear current parameters list

Public function getValue(key: string; default: string = ''): string; overload;

Get the string value for key parameter with an empty string as default value

Public function getValue(key: string; default: boolean = False): boolean; overload;

Get the boolean value for key parameter with False as default value

Public function getValue(key: string; default: cardinal = 0): cardinal; overload;

Get the cardinal value for key parameter with zero as default value

Public function getValue(key: string; default: integer = 0): integer; overload;

Get the integer value for key parameter with zero as default value

Public function getValue(key: string; default: single = 0): single; overload;

Get the single value for key parameter with zero as default value

Public function getValue(key: string; default: TDateTime = 0): TDateTime; overload;

Get the TDateTime value for key parameter with December 30th 1899 at 12:00 as default value

Public function getValue(key: string; default: TJSONValue = nil) : TJSONValue; overload;

Get the JSON value for key parameter with nil as default value

Public procedure setValue(key, Value: string); overload;

Set the value for key parameter as string

Public procedure setValue(key: string; Value: boolean); overload;

Set the value for key parameter as boolean

Public procedure setValue(key: string; Value: cardinal); overload;

Set the value for key parameter as cardinal

Public procedure setValue(key: string; Value: integer); overload;

Set the value for key parameter as integer

Public procedure setValue(key: string; Value: single); overload;

Set the value for key parameter as single

Public procedure setValue(key: string; Value: TDateTime); overload;

Set the value for key parameter as TDateTime

Public procedure setValue(key: string; Value: TJSONValue); overload;

Set the value for key parameter as TJSONValue

Public procedure setFolderName(AFolderName: string; AReload: boolean = true);

Change the folder where is the parameter file.

To change the file name, use setFilePath() instead of setFolderName().

Parameters
AFolderName
Absolute folder path where you want to save the parameter file.
AReload
If set to True (by default), call the Load procedure after changing the folder.
Public procedure setFilePath(AFilePath: string; AReload: boolean = true);

Change the folder where is the parameter file.

If you only want to change the path to the parameter file, use setFolderName procedure instead of this one.

Parameters
AFilePath
Absolute file path (drive+folder+file name+extension) to the parameter file you want to use.
AReload
If set to True (by default), call Load procedure after changing the file path.
Public procedure InitDefaultFileNameV2(Const AEditor, ASoftware: string; AReload: boolean = true);

Initialise the folder and the filename with a new default tree: => "Documents / Editor / Software" for DEBUG and iOS => "AppData (HomePath) / Editor / Software" in RELEASE (except iOS)

Public procedure MoveToFilePath(ANewFilePath: string; ASave: boolean = true; ACreateFolder: boolean = False);

Move actual parameter file to the new file.

Parameters
ANewFilePath
Absolute file path (drive+folder+file name+extension) to the parameter file you want to use.
ASave
If set to True, save actual values to the parameter file. If set to false, just move the parameter file to it's new folder/filename.
ACreateFolder
If set to True, create the folder of file parameter if it doesn't exists.
Public function getFilePath: string;

Return the absolute path to the parameter file (drive+folder+file name+extension)

Public function ToJSON: string;

Return the current parameters as a serialized JSON object.

Public function AsJSONObject(AClone: boolean = true): TJSONObject;

Return the current parameters as a JSON object

Parameters
AClone
If set to True (by default), the result is a clone of actual object. Free it when you have finished to work with it or you'll have memory leaks in your projects. If set to False, the result is a reference to the internal JSON object. All changes are made to it. Don't destroy it or you'll have Access Violation exception.
Public procedure Remove(key: string);

Retire une clé des paramètres

Public function HasChanged: boolean;

Returns True if a setting has changed and not been saved.

Public procedure BeginUpdate;

Allow parameters changes but delay the Save operation to the EndUpdate call.

If you call BeginUpdate you MUST call its EndUpdate. Use a try... finally... end !

Public procedure EndUpdate(const AutoSaveChanges: boolean = true);

Closes the block of code started with BeginUpdate. If you did some changes, it saves them by default.

If you call BeginUpdate you MUST call its EndUpdate. Use a try... finally... end !

Properties

Public property onBeforeLoadEvent: TParamsLoadSaveEvent read FonBeforeLoadEvent write SetonBeforeLoadEvent;

Called before loading the settings file.

Also called for Cancel operation (which reload the file).

Public property onBeforeLoadProc: TParamsLoadSaveProc read FonBeforeLoadProc write SetonBeforeLoadProc;
 
Public property onAfterLoadEvent: TParamsLoadSaveEvent read FonAfterLoadEvent write SetonAfterLoadEvent;

Called after loading the settings file

Also called for Cancel operation (which reload the file).

Public property onAfterLoadProc: TParamsLoadSaveProc read FonAfterLoadProc write SetonAfterLoadProc;
 
Public property onBeforeSaveEvent: TParamsLoadSaveEvent read FonBeforeSaveEvent write SetonBeforeSaveEvent;

Called before saving the settings file

Public property onBeforeSaveProc: TParamsLoadSaveProc read FonBeforeSaveProc write SetonBeforeSaveProc;
 
Public property onAfterSaveEvent: TParamsLoadSaveEvent read FonAfterSaveEvent write SetonAfterSaveEvent;

Called after saving the settings file

Public property onAfterSaveProc: TParamsLoadSaveProc read FonAfterSaveProc write SetonAfterSaveProc;
 
Public property onCryptEvent: TParamsCryptEvent read FonCryptEvent write SetonCryptEvent;

Called before saving the parameters in a file (and after onBeforeSave). If crypted, the file is saved as a binary format. If uncrypted, the file is saved as a JSON text file.

Public property onCryptProc: TParamsCryptProc read FonCryptProc write SetonCryptProc;
 
Public property onDecryptEvent: TParamsDecryptEvent read FonDecryptEvent write SetonDecryptEvent;

Called after loading the parameters from a file (and before onAfterLoad). If crypted, the file is saved as a binary format. If uncrypted, the file is saved as a JSON text file.

Public property onDecryptProc: TParamsDecryptProc read FonDecryptProc write SetonDecryptProc;
 
Public property PortableMode: boolean read FPortableMode write SetPortableMode;

Portable mode : if true nothing is saved nor loaded. Default value is false.

My libraries for Delphi (c) 1990-2025 Patrick PREMARTIN - Powered by PasDoc
Generated by PasDoc 0.16.0.