'Check' function is executing multiple times in Inno Setup

后端 未结 1 437
广开言路
广开言路 2021-02-10 16:51

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. C

相关标签:
1条回答
  • 2021-02-10 17:09

    Quoting 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.

    So the behavior is as designed.

    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; 
    
    0 讨论(0)
提交回复
热议问题