在Delphi 2007中,我可以使用以下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应用程序。
我还尝试了返回一个TStrings指针的“ Keys”值。在这里,我还获得了FileVersion字符串,但它始终为“ 1.0.0.0”。
我想这与对各种平台和配置的支持有关,但是我找不到任何有关它现在应该如何工作的文档。我还搜索了ToolsAPI.pas中的“版本”和“发行版”,但没有发现可疑之处。
关于如何在Delphi 10.2中获取版本信息的任何提示?
版本信息的有效值存储在用于构建配置和平台的单独配置中。要访问配置,请首先获取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中检索当前平台和配置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句