1

When writing the Delphi expert using ToolsAPI, we may use GetEnvironmentVariable to retrieve the environment variables available to the current Delphi IDE process. However, this only works if the variables are define in your current user account setting or in Delphi's environment variables setting under

Tools | Options | Environment Options | Environment Variables.

Some variables like $(Config) in Delphi 2010 / XE are available for used but it doesn't appear as environment variables. We may get a list of variables by turn on "Diagnostic" in Verbosity setting. The $(Config) variable appears in Diagnostic output when compiling a project in Delphi IDE.

Is there a way to retrieve the value of $(Config) in ToolsAPI?

Chau Chee Yang
  • 18,422
  • 16
  • 68
  • 132

1 Answers1

4

The project's ProjectOptions property can be cast to IOTAProjectOptionsConfigurations.

var
  Project: IOTAProject;
begin
  // ... obtain reference to the project
  ShowMessage((Project.ProjectOptions as IOTAProjectOptionsConfigurations).ActiveConfigurationName);
end;
Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • What if I need to retrieve other variable's value that not define in environment variables? The reason I ask this is I try to do a workaround solution to fix an IDE bug: http://qc.embarcadero.com/wc/qcmain.aspx?d=92507 – Chau Chee Yang Mar 24 '11 at 14:42
  • That probably depends on what the "other variables" are. – Ondrej Kelle Mar 24 '11 at 14:43
  • If we have more than one build configurations, e.g.: "debug" and "release", we may perform "release" build in IDE while "debug" is the active configuration. In the answer you given, I never have chance to get the value of $(Config) as "release", it always return "debug" in this case. – Chau Chee Yang Mar 25 '11 at 08:35
  • `ActiveConfiguration` returns the active configuration. To enumerate all defined configurations use the `ConfigurationCount` and `Configurations` properties of the `IOTAProjectOptionsConfigurations` interface. – Ondrej Kelle Mar 25 '11 at 09:00
  • I am aware of the ConfigurationCount and Configurations properties. I wish to retrieve the actual configuration when build a project in my Toolsapi expert. If I can retrieve the value of $(Config) during runtime, then my problem is solved. The ActiveConfiguration is not always the build configuration for current compilation task. – Chau Chee Yang Mar 25 '11 at 09:20
  • The actual configuration? Sorry, I don't know what you mean by that. Or "the value of $(Config) during runtime". It's actually runtime of the IDE, or runtime of the compiled project? It would help if you could ask more clearly. Perhaps you need to write and register a compile notifier by implementing `IOTAProjectCompileNotifier`? I have no idea from what you wrote. – Ondrej Kelle Mar 25 '11 at 09:33
  • Let me rephrase. I have 2 build configurations: "debug" and "release". "debug" is the active configuration. ActiveConfiguration will always return "debug" if I invoke the function in IDE toolsapi runtime. If I right click on "release" build (not the active configuration) and select build, how may I get the configuration of "release"? I have tried IOTAProjectCompileNotifier and it almost work. If I invoke AddCompileNotifier and RemoveCompileNotifier for few times, the IDE prompt Access violation in module 'delphicoreide150.bpl'. – Chau Chee Yang Mar 25 '11 at 09:53
  • Yes, I think you need to use the notifier - there you have a chance to determine which configuration is currently being used for the build process. The access violation probably means you're doing something wrong. – Ondrej Kelle Mar 25 '11 at 11:37
  • I have try to figured out what's wrong for day but can't find what's wrong. Can I send you the code to review and hopefully you may point me the mistake I made? Thank you. – Chau Chee Yang Mar 25 '11 at 14:35
  • Post your code here as a question; then you have a better chance to get a good reply. – Ondrej Kelle Mar 25 '11 at 14:58
  • Thanks. I have post a new question in topic [How to implement IOTAProjectCompileNotifier of Delphi's ToolsAPI ?](http://stackoverflow.com/questions/5439666/how-to-implement-iotaprojectcompilenotifier-of-delphis-toolsapi) – Chau Chee Yang Mar 26 '11 at 01:04