在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;