How are Delphi 'environment variables' such as $(BDS) evaluated?
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:
@SET BDS=C:\Program Files (x86)\Embarcadero\RAD Studio\7.0
@SET BDSCOMMONDIR=C:\Users\Public\Documents\RAD Studio\7.0
@SET FrameworkDir=C:\Windows\Microsoft.NET\Framework\v2.0.50727
@SET FrameworkVersion=v2.0.50727
@SET FrameworkSDKDir=
@SET PATH=%FrameworkDir%;%FrameworkSDKDir%;%PATH%
@SET LANGDIR=EN
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 a TStringList
and I'm applying a simple RegEx to identify the assignments.
My routine that expands those $(Nam)
style expressions includes a special case for the DELPHI
name, to handle Delphi7: If I see that, I replace it with the installation path of the IDE.
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.