Inno Setup ParseVersion 不能从 [代码] 调用

Inno Setup ParseVersion is not callable from [Code]

例如,宏ParseVersionRemoveBackslash都在ISPPBuiltins.iss中声明。如果我尝试从 [Code]:

中调用两者
function InitializeSetup: Boolean;
var
    Major, Minor, Rev, Build: Integer;
begin
    RemoveBackslash('123\');
    ParseVersion('12345', Major, Minor, Rev, Build);
end;

RemoveBackslash 编译正常,但添加 ParseVersion 会导致编译器错误:

Unknown identifier 'ParseVersion'"

当另一个宏声明的一部分时,ParseVersion 似乎编译正常,只是不是来自 [Code]。我应该可以这样称呼它吗?

Change Log(对于 6.1.x)中提到:

Support function GetFileVersion and ParseVersion have been renamed to GetVersionNumbersString and GetVersionComponents respectively. The old names are still supported, but it is recommended to update your scripts to the new names and the compiler will issue a warning if you don't.

所以升级的时候要注意这一点。但正如您所说,这些是 Inno Setup Preprocessor (ISPP) 函数。关于 Pascal Script 部分,Support Function Reference.

中没有列出任何内容

其他人可能能够对此提供更多见解,或提供解决方法,但您可能必须在信息设置中请求该功能 forum

正如@Andrew 已经写的那样,ParseVersion(或者实际上是因为 Inno Setup 6.1, the GetVersionComponents)是一个预处理器函数。因此必须使用预处理器指令调用它,并将其结果存储到预处理器变量中。

#define Major
#define Minor
#define Rev
#define Build
#expr GetVersionComponents("C:\path\MyProg.exe", Major, Minor, Rev, Build)

如果您需要使用 Pascal 脚本中的变量 Code,您再次需要使用预处理器语法。例如:

[Code]

function InitializeSetup: Boolean;
begin
  MsgBox('Version is: {#Major}.{#Minor}.{#Rev}.{#Build}.', mbInformation, MB_OK);
  Result := True;
end;

以上是正确的,如果你真的想在编译时提取版本号。如果您真的想在 Code 部分执行此操作,即在安装时,您必须使用 Pascal Script support function GetVersionComponents (是的,名称相同,但语言不同):

[Code]

function InitializeSetup: Boolean;
var
  Major, Minor, Rev, Build: Word;
  Msg: string;
begin
  GetVersionComponents('C:\path\MyProg.exe', Major, Minor, Rev, Build);
  Msg := Format('Version is: %d.%d.%d.%d', [Major, Minor, Rev, Build]);
  MsgBox(Msg, mbInformation, MB_OK);
  Result := True;
end;

Pascal 脚本函数 GetVersionComponents 仅在 Inno Setup 6.1 后可用。


RemoveBackslash 在两种情况下都有效,因为 Pascal Script RemoveBackslash and Preprocessor RemoveBackslash.