'Check' 函数在 Inno Setup 中执行了多次
'Check' function is executing multiple times in Inno Setup
我是 Inno Setup 脚本的新手,我正在尝试使用以下代码作为先决条件来安装 .NET Framework 3.5。 Check
函数正在执行多次。有人可以帮我理解为什么吗?
注意:以下代码中的所有其他部分(Setup
、Icons
等)都有正确的内容。
[Files]
Source: "Frameworks\dotnetfx35setup.exe"; DestDir: {tmp}; Flags: deleteafterinstall; \
BeforeInstall: Install35Framework; Check: Framework35IsNotInstalled
[Code]
function IsDotNetDetected(version: string; service: Cardinal): boolean;
begin
Result := { ... };
end;
function Framework35IsNotInstalled: Boolean;
begin
if IsDotNetDetected('v3.5', 1) then
begin
MsgBox('Framework35IsNotInstalled: FALSE ', mbConfirmation, MB_YESNO);
Result := False;
end else begin
MsgBox('Framework35IsNotInstalled: TRUE ', mbConfirmation, MB_YESNO);
Result := True;
end;
end;
procedure Install35Framework;
begin
{ ... }
end;
引用 Check parameter documentation:
Setup might call each check function several times, even if there's only one entry that uses the check function. If your function performs a lengthy piece of code, you can optimize it by performing the code only once and 'caching' the result in a global variable.
因此行为符合设计。
并且由于您的代码非常简单,我什至认为它不需要任何优化。跑几次就好了
如果不是,你可以这样优化:
var
Framework35IsNotInstalledCalled: Boolean;
Framework35IsNotInstalledResult: Boolean;
function Framework35IsNotInstalled: Boolean;
begin
if not Framework35IsNotInstalledCalled then
begin
Framework35IsNotInstalledResult := IsDotNetDetected('v3.5', 1);
Framework35IsNotInstalledCalled := True;
end;
Result := Framework35IsNotInstalledResult;
end;
我是 Inno Setup 脚本的新手,我正在尝试使用以下代码作为先决条件来安装 .NET Framework 3.5。 Check
函数正在执行多次。有人可以帮我理解为什么吗?
注意:以下代码中的所有其他部分(Setup
、Icons
等)都有正确的内容。
[Files]
Source: "Frameworks\dotnetfx35setup.exe"; DestDir: {tmp}; Flags: deleteafterinstall; \
BeforeInstall: Install35Framework; Check: Framework35IsNotInstalled
[Code]
function IsDotNetDetected(version: string; service: Cardinal): boolean;
begin
Result := { ... };
end;
function Framework35IsNotInstalled: Boolean;
begin
if IsDotNetDetected('v3.5', 1) then
begin
MsgBox('Framework35IsNotInstalled: FALSE ', mbConfirmation, MB_YESNO);
Result := False;
end else begin
MsgBox('Framework35IsNotInstalled: TRUE ', mbConfirmation, MB_YESNO);
Result := True;
end;
end;
procedure Install35Framework;
begin
{ ... }
end;
引用 Check parameter documentation:
Setup might call each check function several times, even if there's only one entry that uses the check function. If your function performs a lengthy piece of code, you can optimize it by performing the code only once and 'caching' the result in a global variable.
因此行为符合设计。
并且由于您的代码非常简单,我什至认为它不需要任何优化。跑几次就好了
如果不是,你可以这样优化:
var
Framework35IsNotInstalledCalled: Boolean;
Framework35IsNotInstalledResult: Boolean;
function Framework35IsNotInstalled: Boolean;
begin
if not Framework35IsNotInstalledCalled then
begin
Framework35IsNotInstalledResult := IsDotNetDetected('v3.5', 1);
Framework35IsNotInstalledCalled := True;
end;
Result := Framework35IsNotInstalledResult;
end;