gpt4 book ai didi

.net - “检查”功能在 Inno Setup 中多次执行

转载 作者:行者123 更新时间:2023-12-01 03:20:07 28 4
gpt4 key购买 nike

我是 Inno Setup 脚本的新手,我正在尝试使用以下代码作为先决条件安装 .NET framework 3.5。 Check函数执行多次。有人可以帮我理解为什么吗?

注意:以下代码中的所有其他部分( SetupIcons 等)都有正确的内容。

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

关于.net - “检查”功能在 Inno Setup 中多次执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46037128/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com