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