0

I am getting an "Invalid prototype for 'CheckForFile'". After hours and hours of trying to make setup download and install file (download part works, but I cannot find a way to run downloaded file), I am out of ideas. Why I am getting that error on this?

[Run]
Filename: "{tmp}\AcroRdrDC1800920044_en_US.exe"; Description: "Install Adobe Reader"; Flags: shellexec skipifsilent; BeforeInstall: CheckForFile('{tmp}\AcroRdrDC1800920044_en_US.exe');

[Code]
function CheckForFile(Param: String): Boolean;
begin
  Result := FileExists(Param)
end;
  • If you want to check if file exists, you should use [function FileExists](http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_fileexists) – RobeN Dec 28 '17 at 22:49
  • @RobeN But I am using FileExists() already? – Branislav Mihaljev Dec 28 '17 at 23:04
  • 1
    You should set Procedure for Check not the Function. You can just CheckForFile by a procedure described [Check if file exist in destination or else if doesn't abort the installation](https://stackoverflow.com/questions/12951327/inno-setup-check-if-file-exist-in-destination-or-else-if-doesnt-abort-the-ins) or you can just set a flag to skip if Files Does Not Exist: `Flag: skipifdoesntexist;` which is preferable solution if you don't need any custom event when File is Not Found. – RobeN Dec 29 '17 at 09:14
  • @RobeN Great, thanks! I wasn't aware there is such a flag. Great solution! BTW I saw that question already, but I am getting an error like procedure cannot return value, use function and then I get error Invalid Prototype. – Branislav Mihaljev Dec 29 '17 at 13:51
  • @BranislavMihaljev : you forgot `ExpandConstant(const S: String): String;` use it like `CheckForFile(ExpandConstant('{tmp}\AcroRdrDC1800920044_en_US.exe'));` – moskito-x Dec 29 '17 at 19:16
  • @moskito-x Yes, thanks, I found out that after I posted a question - to evaluate that tmp into the path, but that flag solved the issue and make function obsolete. Thanks to both! – Branislav Mihaljev Dec 30 '17 at 06:27

1 Answers1

1

While there already is some truth within the comments, I'd like to share what I've learned so far anyway, just in case anyone needs it.

My observations are

  • If I use the Check parameter with a function that returns a boolean, there is no Invalid Prototype error
  • If I use the BeforeInstall or AfterInstall parameter with a procedure there is no error either
  • Any other combination will cause the error

This led me to the following conclusion:

When using a procedure or function within the parameters of [Files] entry, Inno Setup creates a prototype for this function or procedure.

  • A procedure prototype for BeforeInstall and AfterInstall, since these do not expect a return value
  • A function : boolean protoype for Check, because this one expects a return value

After processing the [Files] section, the [Code] section is processed. Since a prototype for CheckForFile has already been declared as procedure CheckFile(...); the declaration function CheckFile(...) : boolean does not match the prototype and the error is shown.

Therefor changing the function to a procedure would work techically, but using Check would be the way to go in your case. In cases when we want to execute something before the installation, BeforeInstall is the way to go, but it does not allow returning values.

Paul Kertscher
  • 9,416
  • 5
  • 32
  • 57