|
Storing information - IV An application needs to store various types of information in the registry.
Global settings User-specific settings Dynamic data Global settings:
These settings relate to the path of various related files, driver locations, licensing related information--any information required for the application to run or store context that is user independent. If you look at the way Windows products use the registry, you will find diverse uses.
For example, the tip of the day that is shown in Office products stores the tips in the registry. The list of last used Run commands is stored in the registry. The default location of the spell checker or other components is stored in the registry. Thus any information that is not stored within the application, but is required for the application to run is kept here.
Although each registry entry can contain substantial amount of data, it is recommended that it is kept compact for better performance. The registry can be backed-up to manage cases of corruption of the registry.
User-specific settings:
These are application level settings or configuration values which each user may change separately. For example, the path of a custom dictionary may be different for each user. Things like colour schemes, menu layout, personalisation information can be kept in user-specific settings. These are kept in the HKEY_CURRENT_USER key. Each user's information is stored in the HKEY_USERS key.
Dynamic data:
The HKEY_DYN_DATA\Configuration Manager subkey, sometimes referred to as the hardware tree, is a record in RAM of the current system configuration. The information is drawn from the devices currently installed and loaded, or that failed to load. The hardware tree is created every time the system starts and updates whenever a change occurs to the system configuration. The information that appears in Registry Editor is provided when this key is displayed, so it is never out of date. HKEY_DYN_DATA also contains statistics gathered for various network components in the system. These reside under HKEY_DYN_DATA\PerfStats.
To store a value in the registry for your application, certain guidelines apply.
The registry key you should use is HKEY_LOCAL_MACHINE for global data and HKEY_CURRENT_USER for user-specific information. The name of the subkey should be below the Software subkey and should start with the name of your company. Then, under the company name, specify keys for product and version. Within this, specify the actual parameters and values.
A typical custom defined key structure may look like this:
HKEY_LOCAL_MACHINE Software Mediline Clinic Management Software V 1.0
Within the last key, you can store multiple parameters with values.
Advantages of using the Registry
Earlier, each application used to utilise local text files, typically named as .INI files to store application-specific information. The registry is much better than these INI files for the following reasons:
INI files are text-based, and are limited to 64K in size. The Registry has no size restriction and can include both binary and text values. Information stored in INI files is non-hierarchical and supports only two levels of information (specifically, section headings with a list of key names under each). The Registry is hierarchically arranged. Many INI files contain a myriad of switches and entries that are complicated to configure or are used only by operating system components. The Registry contains more standardised values.
Local variables in documents This is a rather unknown but very useful feature of the Word VBA model. If you are using Word as a programming tool, you can store some variables with values in the document itself. When the document is closed, the values are stored persistently. Reopening the document gives you access to the values again.
This code can illustrate the variables feature in word VBA, immediate window.
activedocument.variables.add "sample", 33 ?activedocument.variables("sample").value33
Tags collection is a similar option in PowerPoint.
This facility is useful for storing document specific custom information in the document itself rather than in an external location. This makes copying and moving the document easy and independent of any other attached information.
Possible uses of this feature in Word:
Store name and other details of each person who edited the document. Store variables related to default values of forms or other template items within the document. Store variables that need to be accessed across two different macros even after the file has been closed. Store information about the usage of templates for usage based charging of custom templates which are sold as products. Keep track of iterative processes which may run across a closure of the document. Mail message Mail message is a place where you store information only about the message. However, in case of workflow type of applications, you may want more information to be stored in the message other than the standard fields like From, To, Subject, CC, Content, etc.
Using the Outlook forms designer, you can create custom properties and attach values to these. The values are an integral part of the message and are carried along with the message when it is delivered to its destination. This means, the data is also stored and forwarded like the base message.
This functionality is extremely useful to create custom forms for workflow type of applications.
|