In Delphi 2007 I can easily get the version information of the current project using the following ToolsAPI calls:
procedure Test; var ProjectOptions: IOTAProjectOptions; Project: IOTAProject; Major: Variant; Minor: Variant; Release: Variant; Build: Variant; begin // GxOtaGetCurrentProject is a function in GExpert's GX_OTAUtils unit that returns the current IOTAProject Project := GxOtaGetCurrentProject; if Assigned(Project) then begin ProjectOptions := Project.ProjectOptions; if Assigned(ProjectOptions) then begin Major := ProjectOptions.Values['MajorVersion']; Minor := ProjectOptions.Values['MinorVersion']; Release := ProjectOptions.Values['Release']; Build := ProjectOptions.Values['Build']; end; end; end;
In Delphi 10.2.3 this will always return the version 184.108.40.206 regardless of the actual version number. This is the "simple" case: A VCL application.
I also tried the "Keys" value which returns a TStrings pointer. There I also get the FileVersion string, but it is always "220.127.116.11".
I guess this has something to do with the support for various platforms and configurations, but I could not find any documentation, on how it should work now. I also searched the ToolsAPI.pas for "version" and "release", but nothing suspicious showed up.
Any hints on how I can get the version information in Delphi 10.2?
The effective values for version info are stored in separate configurations for build configuration and platform. To get access to the configurations, first get an interface to IOTAProjectOptionsConfigurations:
cfgOpt := project.ProjectOptions as IOTAProjectOptionsConfigurations;
Then iterate over each IOTABuildConfiguration:
for I := 0 to cfgOpt.ConfigurationCount - 1 do begin cfg := cfgOpt.Configurations[I]; DoWhatEverWith(cfg); end;
Be aware that each IOTABuildConfiguration can have several platforms and children:
for S in cfg.Platforms do begin DoWhatEverWith(cfg.PlatformConfiguration[S]); end; for I := 0 to cfg.ChildCount - 1 do begin DoWhatEverWith(cfg.Children[I]); end;
Depending on which platform and build configuration is currently selected, different values for version info may be used. The current platform and configuration can be retrieved from the IOTAProject properties CurrentPlatform and CurrentConfiguration.