How are Delphi 'environment variables' such as $(BDS) evaluated?

前端 未结 5 2157
梦谈多话
梦谈多话 2020-12-06 01:17

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

相关标签:
5条回答
  • 2020-12-06 01:36

    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.

    0 讨论(0)
  • 2020-12-06 01:40

    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.

    0 讨论(0)
  • 2020-12-06 01:48

    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 in rsvars.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.

    0 讨论(0)
  • 2020-12-06 01:53

    Thanks, I thought I would add that when I created a new environment variable - (to be used in my DCC_UnitSearchPath as $(VISEMS) ), I observed that it was placed into the registry.

    For a specific example I found it in: Computer\HKEY_CURRENT_USER\Software\Embarcadero\BDS\17.0\Environment Variable

    The "accepted answer" above needs to be updated to reflect the there are version numbers in the registry path, since in my case, the "accepted answer" is incorrect (when it says: HKEY_CURRENT_USER\SOFTWARE\Embarcadero\BDS\8.0\ ) as there is nothing at "BDS\8.0" since 8.0 is not installed on my computer.

    0 讨论(0)
  • 2020-12-06 01:57

    The $() notation for variables is a convention used by MAKE, what Borland used as build tool before switching to MSBuild. (in D2007?)

    0 讨论(0)
提交回复
热议问题