在Delphi2007中,我可以使用以下ToolsAPI调用轻松获取当前项目的版本信息:
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应用程序。
我还尝试了"Keys“值,它返回一个TStrings指针。在那里我也得到了FileVersion字符串,但它始终是"1.0.0.0“。
我猜这与对各种平台和配置的支持有关,但我找不到任何关于它现在应该如何工作的文档。我还在ToolsAPI.pas上搜索了“版本”和“发布”,但没有显示任何可疑的东西。
关于如何在Delphi 10.2中获取版本信息,有什么建议吗?
发布于 2018-07-05 04:53:15
版本信息的有效值存储在构建配置和平台的单独配置中。要访问这些配置,首先要获取IOTAProjectOptionsConfigurations的接口:
cfgOpt := project.ProjectOptions as IOTAProjectOptionsConfigurations;
然后遍历每个IOTABuildConfiguration
for I := 0 to cfgOpt.ConfigurationCount - 1 do
begin
cfg := cfgOpt.Configurations[I];
DoWhatEverWith(cfg);
end;
请注意,每个IOTABuildConfiguration可以有多个平台和子平台:
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中检索当前平台和配置。
https://stackoverflow.com/questions/51180066
复制相似问题