Application Parameters - Documentation
(v2.1) (14th
September 2000)
Ó 2000 by Tom Peiffer
Features - Installation - Properties - Methods - Info - Author
In Delphi, you got powerful classes to access both the Windows registry and
work with INI-files. But there is still a lot of code needed, to work with these
classes. With this component, this becomes much easier. And values from your
inifile or registry key are loaded directly into published properties in a
predefined class. Just call the Load method, or even more easy, set the
LoadOnCreate property to true, and your values are loaded in your published
properties at startup of your application. Make changes to your properties and
call the Save method (or set SaveOnExit to true) and the values are stored back
to registry rsp. inifile. All you need to do is define a new class derived from
TApplValues and define published properties in this class. Now, in the values
property of the component, define for each published property a location where
to store the value (section, subkey, default value if key does not exist etc.).
For the rest, one single line of code is needed:
MyValues := TMyValues.create (Self,AP) ; {supposing
that the component name is AP, and your derived class from TApplValues is called
TMyValues, where MyValues is a pointer to this class }
Confused? Then take a look to the demo project and
you'll discover the power behind it.
Delphi 4: Copy the 3 files (ApplSettings.pas, ApplSettings.dcr, NTReg.pas) in your component directory. In the component menu in Delphi, select Install component and browse to ApplSettings.pas file.
property InifileDirectory : string ;
If you choose to save the values to an inifile, this property indicates the
directory where to store the inifile. Note that this is only the directory. The
name of the inifile is generated automatically. If left blank, the directory
will be the applications working directory.
property LoadOnCreate : boolean ;
If true, all values are loaded from registry rsp.
inifile when you start the application.
property Location : TParamLocation ;
2 options: either choose "User" to store
user dependant properties, or choose "Local" to store machine
dependant properties. This corresponds to the 2 root keys HKEY_CURRENT_USER rsp.
HKEY_LOCAL_MACHINE if you choose the registry as SaveLocation (see SaveTo). If
You save to an inifile, then the file will be named [Username].ini rsp.
Global.ini.
property RegistryMainKey : string ;
The root key in the registry, normally something
like "software\YourApplicationName". Only used when save to the
registry.
property SaveOnExit : boolean ;
If true, all values are stored to registry rsp.
inifile when you close your application ;
property SaveTo : TSaveLocation ;
Choose "Registry" or "IniFile".
(Self-explaining)
property Values : TApplCollection ;
This Collectionlist indicates the properties to be
saved, and where each property is exactly saved.
property Default :
variant ; This is the default value, if a key does not exist in your registry rsp. inifile. |
|
property KeyName :
string ; The name of the key in registry rsp. inifile ; |
|
property PropertyName :
string ; The name of your published property in the class derived from TApplValues. The type of the published property must be one of the following: string, integer, word, float, double, extended, TTime, TDateTime, TDate, boolean. Time and Date types are stored in float format in the registry, and boolean in integer format. |
|
property Section :
string ; Define section names in your inifile. If left blank, the section will be called [GENERAL]. If you store to registry, this property is used to create subkeys from RegistryMainKey. |
{ TApplValues Class }
constructor Create (AOwner : TComponent
;ApplParams : TApplParams) ;
You must inherit a class from TApplValues, where you must define published
properties (public is not enough). At the OnCreate event of your main form, you
may allocate memory for your class by calling this constructor. See the demo
project for more, and you'll see its easy use.
{ TApplValues & TApplParams Classes }
procedure Load ;
Loads the property values from registry rsp. inifile.
procedure Save ;
Saves the property values to registry rsp. inifile.
TApplParams is cardware. Do with it whatever you want. All you have to do for complete legal
use is sending me a postcard from your country or town. You find my
addresses further down. For me, this is an appreciation that may encourage
me for
writing other components. If you do so, you may use the component in the way you like. You
can change the source of the component and add other features if you want, but the
author
does not take any warranty for bad use or eventual program crashes or data loss. If you
change the source, be fair enough to leave the names and copyrights of me in the source
header and mail me your changes.
For any comments or suggestions, you may get in contact with the author.
The code is for sure not bugfree, and bad property values are simply punished by
an exception during runtime (e.g. indicating a propertyname that does not exist
only can be discovered during runtime). Hope you'll like the component.
Tom Peiffer (Physics student at University of
Kaiserslautern)
Hirtenweg 2
D-67661 Kaiserslautern
Germany
EMail: peiffer@bigfoot.com