在Inno Setup Pascal脚本中,在运行时评估预处理器中的数据集合 [英] Evaluate a collection of data from preprocessor on run time in Inno Setup Pascal Script

查看:48
本文介绍了在Inno Setup Pascal脚本中,在运行时评估预处理器中的数据集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Code部分中获取Inno Setup定义值,但不能在{#VersionTool1}中获取.我需要动态传递已定义的名称,因为其中有很多(我想避免使用大号开关).我尝试了SetupSetting,但它不在设置"部分中(在它之前).有什么办法吗?

I am trying to get Inno Setup define value in Code section but not with {#VersionTool1}. I need to pass defined name dynamically, because there are a lot of them (I want to avoid large switch case). I tried SetupSetting but it's not in Setup section (it's before it). Is there any way to do this?

#define VersionTool1 2019.01.1111
#define VersionTool2 2020.02.2111

...

[Code]

procedure SetSelectedTool(ToolName: String);
var
  CurrentTool: string;
begin
  ...
  CurrentTool := 'Version' + ToolName;
  CurrentToolVersion := {#CurrentTool};
  ...
end;

局部变量CurrentTool的值例如是'VersionTool1',我想获取VersionTool1预处理器变量的值,即2020.02.2111.

Value of local variable CurrentTool wil for example be 'VersionTool1' and I want to get value of VersionTool1 preprocessor variable which is 2020.02.2111.

推荐答案

这是不可能的,请参见在Inno中运行时评估预处理器宏设置Pascal脚本.

It's not possible, see Evaluate preprocessor macro on run time in Inno Setup Pascal Script.

但是还有其他解决方案.

But there are other solutions.

例如:

[Code]
var
  ToolNames: TStringList;
  ToolVersions: TStringList;

function InitializeSetup(): Boolean;
begin
  ToolNames := TStringList.Create;
  ToolVersions := TStringList.Create;

  #define AddToolVersion(Name, Version) \
    "ToolNames.Add('" + Name + "'); ToolVersions.Add('" + Version +"');"

  #emit AddToolVersion('Tool1', '2019.01.1111')
  #emit AddToolVersion('Tool2', '2020.02.2111')
  { ... }

  Result := True;
end;

(当然,只有当您实际上不对版本号进行硬编码,而是使用只有预处理程序才能执行的代码时,上述内容才有意义-像GetStringFileInfo一样,我从您的评论中了解到您打算这样做)

(of course, the above makes sense only if you actually do not hardcode the version numbers, but use a code that only a preprocessor can do – something like GetStringFileInfo, what I've understood from your comments that you plan to)

然后您可以拥有类似的功能:

And then you can have a function like:

function GetToolVersion(ToolName: string): string;
var
  I: Integer;
begin
  I := ToolNames.IndexOf(ToolName);
  if I >= 0 then Result := ToolVersions[I];
end;

这篇关于在Inno Setup Pascal脚本中,在运行时评估预处理器中的数据集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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