如何在 Inno Setup 中使用 PrepareToTinstall 函数的 NeedsRestart 参数?
How to use NeedsRestart parameter of PrepareToTinstall function in Inno Setup?
在 AllPagesExample.iss
示例文件中有这一部分:
function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
if SuppressibleMsgBox('Do you want to stop Setup at the Preparing To Install wizard page?', mbConfirmation, MB_YESNO, IDNO) = IDYES then
Result := 'Stopped by user';
end;
如果PrepareToTinstall
是一个事件函数,我自己又不调用它,我怎么给它传递NeedsRestart
参数呢?
NeedsRestart
参数是passed by a reference(var
关键字)。因此它的值是从函数 return 中编辑的,类似于函数本身的 return 值 (Result
)。
正如 documentation 所说:
Return a non empty string to instruct Setup to stop at the Preparing to Install wizard page, showing the returned string as the error message. Set NeedsRestart
to True (and return a non empty string) if a restart is needed. If Setup is stopped this way, it will exit with a dedicated exit code as described in Setup Exit Codes.
因此,您要做的是为参数分配一个值,一旦事件函数退出,Inno Setup 就会相应地采取行动。
function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
Result := '';
if DoWeNeedRestartBeforeInstalling then
begin
Result := 'You need to restart your machine before installing';
NeedsRestart := True;
end;
end;
在 AllPagesExample.iss
示例文件中有这一部分:
function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
if SuppressibleMsgBox('Do you want to stop Setup at the Preparing To Install wizard page?', mbConfirmation, MB_YESNO, IDNO) = IDYES then
Result := 'Stopped by user';
end;
如果PrepareToTinstall
是一个事件函数,我自己又不调用它,我怎么给它传递NeedsRestart
参数呢?
NeedsRestart
参数是passed by a reference(var
关键字)。因此它的值是从函数 return 中编辑的,类似于函数本身的 return 值 (Result
)。
正如 documentation 所说:
Return a non empty string to instruct Setup to stop at the Preparing to Install wizard page, showing the returned string as the error message. Set
NeedsRestart
to True (and return a non empty string) if a restart is needed. If Setup is stopped this way, it will exit with a dedicated exit code as described in Setup Exit Codes.
因此,您要做的是为参数分配一个值,一旦事件函数退出,Inno Setup 就会相应地采取行动。
function PrepareToInstall(var NeedsRestart: Boolean): String;
begin
Result := '';
if DoWeNeedRestartBeforeInstalling then
begin
Result := 'You need to restart your machine before installing';
NeedsRestart := True;
end;
end;