简体   繁体   English

Inno 设置:无效的原型

[英]Inno Setup: Invalid Prototype

I am getting an "Invalid prototype for 'CheckForFile'".我收到“'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;

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如果我将Check参数与返回booleanfunction一起使用,则不会出现Invalid Prototype错误
  • If I use the BeforeInstall or AfterInstall parameter with a procedure there is no error either如果我将BeforeInstallAfterInstall参数与procedure一起使用,则也没有错误
  • 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.[Files]条目的参数中使用过程或函数时, Inno Setup会为此函数或过程创建原型。

  • A procedure prototype for BeforeInstall and AfterInstall , since these do not expect a return value BeforeInstallAfterInstallprocedure原型,因为它们不期望返回值
  • A function : boolean protoype for Check , because this one expects a return value一个函数: Checkfunction : boolean原型,因为这个函数需要一个返回值

After processing the [Files] section, the [Code] section is processed.处理完[Files]部分后,将处理[Code]部分。 Since a prototype for CheckForFile has already been declared as procedure CheckFile(...);因为CheckForFile的原型已经被声明为procedure CheckFile(...); the declaration function CheckFile(...) : boolean does not match the prototype and the error is shown.声明function CheckFile(...) : boolean与原型不匹配并显示错误。

Therefor changing the function to a procedure would work techically, but using Check would be the way to go in your case.因此,将功能更改为过程将在技术上起作用,但在您的情况下使用Check将是可行的方法。 In cases when we want to execute something before the installation, BeforeInstall is the way to go, but it does not allow returning values.如果我们想在安装之前执行某些操作,可以使用BeforeInstall ,但它不允许返回值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM