Mega Code Archive

 
Categories / Delphi / Examples
 

Tidy component library for easy migrations or builds

Controlling your Library Path can be benefitial for a number of reasons, easy reading, sharing network components/libraries, or even for escrowing projects. There is a relatively way to control the many component libraries we have available for our use in Delphi. An example of its syntax can be seen at the top of the Delphi Library Path dialog, as seen below: This $(DELPHI) syntax is easily replicated for our own use. For example, I try to keep my components very tightly version controlled, and all in one directory. My reason for this approach is a nasty past experience of building an escrow for a customer was a painful task to build, test, and maintain. However, this neat-freak approach helps us build an easily maintained approach to the Library entries. So what is this $(DELPHI) comment? Well it is a reference to an Environment Variable. As such we can create our own reference by right-clicking on My Computer, selecting Properties, and selecting the Advanced tab. On this tabsheet we can see a section relating to Environment Variables. If you press the Environment Variables button, you can see a list of the available variables currently used on the system. To help me organise my Library Path, I created a variable called COMN_COMP, which I pointed to my directory inside which all my main components reside. From this point we can start up Delphi and actually use $(COMN_COMP) to replace that common path information on all the directory listings. This can shorten the length of the strings listed in the Library Path. However, that isn't the major benefit as I see things. The major benefit is that the information now held in the Registry key which represents the Library Path is now very portable. You can copy this registry value, store it in a .reg file, and import it into a test machine. Configure the environment variable, and you are almost up and running. The same trick can be used with the Known IDE Packages registry key, so you can even specify the packages to be loaded in exactly the same manner. In fact this is the approach Delphi itself uses to load the core IDE packages for the components that come with Delphi, as can be seen in the appropriate registry key: It also really helps when you have to recover from a system failure to be able to get up and running very quickly again as well. As the majority of us IT people do tend to neglect backups for our own data, this might be helpful to any serious Delphi Developer. ;)