I'm making some tidy installers for our internal libraries (instead of just opening the DPK's and clicking 'install' and getting in a mess later...) and this has caused me to have to understand how to get at various Delphi variables such as Known Packages, the registry RootDir value etc.
I see that within Delphi there are a number of variables that you can use (within a search path for example) such as $(BDS) etc. When I look into my machine environment variables I dont see these, either in system or current user.
My questions are:
- Is Delphi doing something internal to expand $(BDS) etc itself? Or can I use these externally in some way (eg looked up in the registry).
- Why is the notation $(xxxx) within a search path and not %xxxx% as with an envirnment variable? Thanks
The $() notation for variables is a convention used by MAKE, what Borland used as build tool before switching to MSBuild. (in D2007?)
David is right that these variables are specific to Delphi (and C++ Builder), and they are not available as "normal" environment variables.
However, they can be looked up in the registry. The key is:
HKCU\Software\<Borcadero>\BDS\<version>\Environment Variables
.Any custom "environment" variables that you add can be found here as well. For example I have a $(MVC) variable to point to the folder where all my components(' versions) can be found.
At work we use the registry to look up the values in a script/app combination to convert dprojs to cfg files for our build server which uses the command line compiler. (As we don't use the IDE on the build machine, we have added our custom Delphi environment variables to the registry manually).
Update
Actually, the Environment Variables key is used for user defined environment variables and for overrides of the "standard" BDS environment variables. The default values of any $(BDS*) environment variable is nowhere to be found in the registry...
So, current knowledge says, if you want to get your hands on the values for the $(BDS*) vars, you would have to override the default values and read the ones you specified from the Environment Variables key.
1) They are simply environment variables which Delphi sets for its own process and you can retrieve them with GetEnvironmentStrings from a design package installed in the IDE; here's an example.
If your installer is a separate executable, you can still (more or less reliably) guess where to get some of the values:
BDS
:RootDir
value in the registry, e.g.HKEY_CURRENT_USER\SOFTWARE\Embarcadero\BDS\8.0\
BDSCOMMONDIR
: in older versions (Delphi 2007, I guess) this was a global environment variable, set by the Delphi installer. In later versions you can find it inrsvars.bat
.Some others might probably be derived, e.g.:
BDSLIB
:$(BDS)\lib
BDSINCLUDE
:$(BDS)\include
User-defined variables (defined in Delphi's Environment Options dialog) are stored in the
Environment Variables
registry subkey.2) The
$(...)
notation is IMHO simply better because it has distinct opening and closing delimiters, it's easier to work with for search/replace operations and also more readable.I'm working on a bit of command line build automation (because I want to move away from Final Builder) so I had to deal with those special variables. To invoke the command-line compiler we're supposed to either invoke the command prompt using the "RAD Studio Command Prompt" from the Start menu, or to include the "rsvars.bat" script into our own scripts.
That rsvars.bat script looks like this:
As you can notice, the very special BDS variable is set in there, as well as some others. The BDS path corresponds with the BDS installation path in the Registry, but I decided to read it from the
rsvars.bat
script, hoping it'll be more future-proof. So I'm essentially reading the.bat
file into aTStringList
and I'm applying a simple RegEx to identify the assignments.My routine that expands those
$(Nam)
style expressions includes a special case for theDELPHI
name, to handle Delphi7: If I see that, I replace it with the installation path of the IDE.