Inno Setup中多次执行“检查"功能 [英] 'Check' function is executing multiple times in Inno Setup

查看:162
本文介绍了Inno Setup中多次执行“检查"功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Inno Setup脚本的新手,并且我尝试使用以下代码作为必备软件来安装.NET Framework 3.5. Check函数正在执行多次.有人可以帮我理解为什么吗?

I am new to Inno Setup scripting and I am trying to install .NET framework 3.5 using below code as a prerequisite. The Check function is executing multiple times. Can some one please help me understand why?

注意:以下这段代码中的所有其他节(SetupIcons等)都有适当的内容.

Note: All other sections (Setup, Icons, etc) in this below code are having proper contents.

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

推荐答案

引用检查参数文档:

即使只有一个条目使用检查功能,安装程序也可能会多次调用每个检查功能.如果您的函数执行了一段冗长的代码,则可以通过仅执行一次代码并将结果缓存"到全局变量中来对其进行优化.

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.

所以行为是按设计的.

由于您的代码非常简单,我什至认为它不需要任何优化.如果可以运行几次,那是完全可以的.

And as your code is quite simple, I do not even think it needs any optimization. It's perfectly ok, if it runs few times.

不是吗,您可以像这样优化它:

Were it not, you can optimize it like this:

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中多次执行“检查"功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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