Class TParams

Unit

Declaration

type TParams = class(TObject)

Description

Use TParams with its class methods if you only want to manage one settings file. If you need more than 1 file to store your settings in the same project, crreate instances of TParamsFile instead of using TParams.

TParams is here for compatibility with old projects.

Hierarchy

Overview

Methods

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

Properties

Public class property onBeforeLoadEvent: TParamsLoadSaveEvent read GetonBeforeLoadEvent write SetonBeforeLoadEvent;
Public class property onBeforeLoadProc: TParamsLoadSaveProc read GetonBeforeLoadProc write SetonBeforeLoadProc;
Public class property onAfterLoadEvent: TParamsLoadSaveEvent read GetonAfterLoadEvent write SetonAfterLoadEvent;
Public class property onAfterLoadProc: TParamsLoadSaveProc read GetonAfterLoadProc write SetonAfterLoadProc;
Public class property onBeforeSaveEvent: TParamsLoadSaveEvent read GetonBeforeSaveEvent write SetonBeforeSaveEvent;
Public class property onBeforeSaveProc: TParamsLoadSaveProc read GetonBeforeSaveProc write SetonBeforeSaveProc;
Public class property onAfterSaveEvent: TParamsLoadSaveEvent read GetonAfterSaveEvent write SetonAfterSaveEvent;
Public class property onAfterSaveProc: TParamsLoadSaveProc read GetonAfterSaveProc write SetonAfterSaveProc;
Public class property onCryptEvent: TParamsCryptEvent read GetonCryptEvent write SetonCryptEvent;
Public class property onCryptProc: TParamsCryptProc read GetonCryptProc write SetonCryptProc;
Public class property onDecryptEvent: TParamsDecryptEvent read GetonDecryptEvent write SetonDecryptEvent;
Public class property onDecryptProc: TParamsDecryptProc read GetonDecryptProc write SetonDecryptProc;
Public class property PortableMode: boolean read GetPortableMode write SetPortableMode;

Description

Methods

Public class procedure Save;

Save current parameters to actual parameter file

Public class procedure Load;

Load parameters from actual parameter file

Public class procedure Cancel;

Cancel current changes and reload previous saved values

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

Delete the file where settings are stored.

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

Public class procedure Clear;

Clear current parameters list

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

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

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

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

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

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

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

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

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

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

Public class 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 class function getValue(key: string; default: TJSONValue = nil) : TJSONValue; overload;

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

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

Set the value for key parameter as string

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

Set the value for key parameter as boolean

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

Set the value for key parameter as integer

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

Set the value for key parameter as cardinal

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

Set the value for key parameter as single

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

Set the value for key parameter as TDateTime

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

Set the value for key parameter as TJSONValue

Public class 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 class 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 class 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 class 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 class function getFilePath: string;

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

Public class function ToJSON: string;

Return the current parameters as a serialized JSON object.

Public class function AsJSONObject: TJSONObject;

Return the current parameters as a JSON object

Public class procedure Remove(key: string);

Retire une clé des paramètres

Public class function HasChanged: boolean;
 
Public class 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 class 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 class property onBeforeLoadEvent: TParamsLoadSaveEvent read GetonBeforeLoadEvent write SetonBeforeLoadEvent;

Called before loading the settings file

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

Public class property onBeforeLoadProc: TParamsLoadSaveProc read GetonBeforeLoadProc write SetonBeforeLoadProc;
 
Public class property onAfterLoadEvent: TParamsLoadSaveEvent read GetonAfterLoadEvent write SetonAfterLoadEvent;

Called after loading the settings file

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

Public class property onAfterLoadProc: TParamsLoadSaveProc read GetonAfterLoadProc write SetonAfterLoadProc;
 
Public class property onBeforeSaveEvent: TParamsLoadSaveEvent read GetonBeforeSaveEvent write SetonBeforeSaveEvent;

Called before saving the settings file

The finalization of this unit calls the TParams.Save. If you have a BeforeSaveEvent or BeforeEventProc, beware of potential access violation by using something perhaps already destroyed.

Public class property onBeforeSaveProc: TParamsLoadSaveProc read GetonBeforeSaveProc write SetonBeforeSaveProc;
 
Public class property onAfterSaveEvent: TParamsLoadSaveEvent read GetonAfterSaveEvent write SetonAfterSaveEvent;

Called after saving the settings file

The finalization of this unit calls the TParams.Save. If you have a BeforeSaveEvent or BeforeEventProc, beware of potential access violation by using something perhaps already destroyed.

Public class property onAfterSaveProc: TParamsLoadSaveProc read GetonAfterSaveProc write SetonAfterSaveProc;
 
Public class property onCryptEvent: TParamsCryptEvent read GetonCryptEvent 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 class property onCryptProc: TParamsCryptProc read GetonCryptProc write SetonCryptProc;
 
Public class property onDecryptEvent: TParamsDecryptEvent read GetonDecryptEvent 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 class property onDecryptProc: TParamsDecryptProc read GetonDecryptProc write SetonDecryptProc;
 
Public class property PortableMode: boolean read GetPortableMode write SetPortableMode;

Portable mode : if true nothing is done on the storage. Default value is false.

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