为什么要使用 InitializeSetup ?
如果要在向导启动之前有条件地退出设置,请不要使用带有异常引发InitializeWizard的事件函数。Abort您将浪费时间,需要创建整个向导表单。请改用InitializeSetup事件函数。在那里,您可以引发Abort异常或更好地将 False 返回到其布尔结果,并按预期退出函数 - 最终效果肯定是相同的。
在内部,当您从脚本中返回 False 时,该InitializeSetup函数只会引发此异常。Abort与InitializeWizard事件相反,当InitializeSetup事件被触发时,向导表单还没有创建,所以你不会浪费时间,也不会使用系统资源。
代码示例:
在下面的伪代码中,您需要有一个函数UserDownloadedWrongVersion,如果您返回 True,则设置将终止,否则不会发生任何事情。
[Code]
function UserDownloadedWrongVersion: Boolean;
begin
// make your check here and return True when you detect a wrong
// version, what causes the setup to terminate; False otherwise
end;
function InitializeSetup: Boolean;
begin
Result := not UserDownloadedWrongVersion;
if not Result then
begin
MsgBox('You''ve downloaded the wrong version. Setup will now exit!',
mbError, MB_OK);
Exit; // <-- or use Abort; instead, but there's no need for panic
end;
end;