Hi Al,

If you are storing user settings information I recommend you the following:

- Use a database engine which can be embedded in delphi (not a client
server database). SQLite, NexusDB, FireBird are some of them.
- Create a table with the following structure:

USER_ID INTEGER  or whatever datatype you define your user ids,
SETTING_ID INTEGER,
DATA BLOB

- USER_ID and SETTING_ID should be together your primary key and be indexed
to find your records faster.
- Define constants in your programm for the settings you need.
- Programm a singleton class which should be instantiated on application
start and destroyed on application end.
To use the right file store the path to the database in the registry or
just use the same path where your application runs.
Open the embedded database on create an close it on destroy.
The class should have thread safe public class functions to read/write
settings like

function ReadSetting(const UserId,SettingId: Integer):string;
or
procedure ReadSetting(const UserId,SettingId: Integer; const
aStream:TStream);

procedure WriteSetting(const UserId,SettingId: Integer; aString:string);
or
procedure WriteSetting(const UserId,SettingId: Integer; const
aStream:TStream);

- Many of the vcl components have functions to save the state to a stream
so that it is easy to read/write them with the appropriate functions
(ReadToStream, WriteToStream).
- In other cases you surely would like just to save settings as string, the
corresponding functions should create a BlobField and put the string in the
Blob or just use the property AsString from TField.
- You can expand the class with functions which return other datatypes like
integer,double,datetime, etc.

This solution lets you also use XML where needed, you can always save XML
settings as string.

Furthermore if you need to persist the settings to a Server you can
programm a function in your application server to save the whole Database
file and make it available for other users (FireBird and SQLite use only
one file for the database).

I prefer to work with such a database instead of with the registry beacause
it is easier to maintain, to transfer to other operating systems and to
distribute with an installation programm; you can query it easily with sql
statements and expand its functionality as needed.

I hope it helps you a little bit more

Agustin Angeles

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to