如何在Delphi 10.2中使用ToolsAPI获取当前项目的版本号 [英] How do I get the version number of the current project using ToolsAPI in Delphi 10.2

查看:185
本文介绍了如何在Delphi 10.2中使用ToolsAPI获取当前项目的版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi 2007中,我可以使用以下ToolsAPI调用轻松获得当前项目的版本信息:

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;

在Delphi 10.2.3中,无论实际版本号如何,它始终将返回版​​本1.0.0.0.这是简单"的情况:一个VCL应用程序.

In Delphi 10.2.3 this will always return the version 1.0.0.0 regardless of the actual version number. This is the "simple" case: A VCL application.

我还尝试了返回一个TStrings指针的"Keys"值.在那里,我还得到了FileVersion字符串,但它始终为"1.0.0.0".

I also tried the "Keys" value which returns a TStrings pointer. There I also get the FileVersion string, but it is always "1.0.0.0".

我想这与对各种平台和配置的支持有关,但是我找不到任何有关它现在应该如何工作的文档.我还搜索了ToolsAPI.pas中的版本"和发行版",但没有发现可疑之处.

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.

关于如何在Delphi 10.2中获取版本信息的任何提示?

Any hints on how I can get the version information in Delphi 10.2?

推荐答案

版本信息的有效值存储在构建配置平台的单独配置中.要访问配置,请首先获取 IOTAProjectOptionsConfigurations 的接口:

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;

然后遍历每个 IOTABuildConfiguration :

  for I := 0 to cfgOpt.ConfigurationCount - 1 do
  begin
    cfg := cfgOpt.Configurations[I];
    DoWhatEverWith(cfg);
  end;

请注意,每个 IOTABuildConfiguration 可以具有多个平台和子代:

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;

根据当前选择的平台和构建配置,可以使用不同的版本信息值.可以从 IOTAProject 属性 CurrentPlatform CurrentConfiguration 中检索当前平台和配置.

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.

这篇关于如何在Delphi 10.2中使用ToolsAPI获取当前项目的版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆