dum*_*uch 4 delphi toolsapi otapi delphi-10.2-tokyo
在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;
Run Code Online (Sandbox Code Playgroud)
在Delphi 10.2.3中,无论实际版本号如何,它都将始终返回版本1.0.0.0.这是"简单"的案例:VCL应用程序.
我还尝试了"Keys"值,它返回一个TStrings指针.在那里我也得到了FileVersion字符串,但它总是"1.0.0.0".
我想这与各种平台和配置的支持有关,但我找不到任何关于它现在应该如何工作的文档.我还搜索了ToolsAPI.pas中的"版本"和"发布",但没有出现任何可疑的内容.
有关如何在Delphi 10.2中获取版本信息的任何提示?
版本信息的有效值存储在构建配置和平台的单独配置中.要访问配置,首先要获得IOTAProjectOptionsConfigurations的接口:
cfgOpt := project.ProjectOptions as IOTAProjectOptionsConfigurations;
Run Code Online (Sandbox Code Playgroud)
然后迭代每个IOTABuildConfiguration:
for I := 0 to cfgOpt.ConfigurationCount - 1 do
begin
cfg := cfgOpt.Configurations[I];
DoWhatEverWith(cfg);
end;
Run Code Online (Sandbox Code Playgroud)
请注意,每个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;
Run Code Online (Sandbox Code Playgroud)
根据当前选择的平台和构建配置,可以使用版本信息的不同值.可以从IOTAProject属性CurrentPlatform和CurrentConfiguration中检索当前平台和配置.
| 归档时间: |
|
| 查看次数: |
897 次 |
| 最近记录: |