Peety
Peety

Reputation: 11

Inno Setup compiler error "Invalid number of parameters" when calling IsDotNetInstalled [Solved]

I'm getting an error compiling my code at the Code section: if not IsDotNetInstalled() then

Invalid number of parameters

I feel like I just overlook something small.

[Code]
var
  ResultCode: Integer;

procedure InitializeSetup();
begin
  // Check if .NET 9.0 is installed before installation starts
  if not IsDotNetInstalled() then
  begin
    MsgBox('The required .NET 9.0 runtime is missing. Installing it now...', mbInformation, MB_OK);
    
    // Run the .NET installer from the temporary directory
    if not Exec(ExpandConstant('{tmp}\dotnet-runtime-9.0.2-win-x64.exe'), '', '', SW_SHOWNORMAL, ewWait, ResultCode) then
    begin
      MsgBox('Failed to install .NET runtime. Error code: ' + IntToStr(ResultCode), mbError, MB_OK);
      Abort; // Abort installation if .NET 9.0 is not installed
    end;
  end;
end;

function IsDotNetInstalled(): Boolean;
var
  version: String;
begin
  Result := False;
  
  // Check for the presence of .NET 9.0 in the registry
  if RegQueryStringValue(HKEY_LOCAL_MACHINE, 
      'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 
      'Version', version) then
  begin
    try
      // Check if the installed version is greater than or equal to 9.0
      if StrToFloat(Copy(version, 1, 3)) >= 9.0 then  
        Result := True;
    except
      Result := False;
    end;
  end;
end;

Thanks in advance!

Upvotes: 1

Views: 59

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202534

In Pascal (Script), you have to define a function, before you can call it. You are calling IsDotNetInstalled, before you define it. Normally you would get "Unknown identifier 'IsDotNetInstalled'". But there's actually a built-in function IsDotNetInstalled, which takes two parameters. That's why you are getting "Invalid number of parameters.".

Move your function definition before InitializeSetup. And better name it differently, not to cause confusion with the built-in function.


(You have other problems in your code, as you will find out)

Upvotes: 0

Related Questions