在 Inno Setup 中单击下一步按钮时验证自定义页面上的数据

Validate data on custom page when Next button is clicked in Inno Setup

我已经设法获得一个基本脚本,用于显示一个向导(使用 CreateInputFilePage),供用户识别我用来更新 XML 文件中某些设置的文件位置。但是,我想对所选文件的输入执行一些基本检查,而不是简单地接受用户提供的任何内容。例如,如果用户在内容无效时尝试按 **Next"*,则显示一个消息框。我不完全确定如何处理向导引起的事件以及如何在继续之前对数据应用任何类型的验证规则到下一个任务。目前,我已经定义了一个简单的 InitializeWizard 过程。

[Code]
var
  Page: TInputFileWizardPage;

procedure InitializeWizard;
begin
  { wizard }
  Page := CreateInputFilePage(
    wpWelcome, 'Select dFile Location', 'Where is dFile located?',
    'Select where dFile.dba file is located, then click Next.' );

  { Add item (with an empty caption) }
  Page.Add('location of dFile.dba', '*.dba|*.*', '.dba' );
end;

然后我在触发 CurStepChanged 事件时恢复文件名和位置,并使用它来更新 XML 文件中的一些设置

procedure CurStepChanged(CurStep: TSetupStep);
var
  dFull: String;
  dPath: String;
  dName: String;
begin
  if (CurStep = ssPostInstall) then
  begin
    { recover dFile location }
    dFull:= Page.Values[0];

    dPath := ExtractFilePath( dFull );
    dName := ExtractFileName( dFull );

    { write dFile location and name to settings.xml }
    UpdateSettingsXML( dPath, 'dFileDirectory' );
    UpdateSettingsXML( dName, 'dFileName' );
  end;
end;

您可以使用自定义 TWizardPageOnNextButtonClick 事件进行验证:

function FileIsValid(Path: string): Boolean;
begin
  Result := { Your validation };
end;

var
  Page: TInputFileWizardPage;

function FilePageNextButtonClick(Sender: TWizardPage): Boolean;
begin
  Result := True;
  if not FileIsValid(Page.Values[0]) then
  begin
    MsgBox('File is not valid', mbError, MB_OK);
    Result := False;
  end;
end;

procedure InitializeWizard;
begin
  Page := CreateInputFilePage(...);

  Page.Add(...);

  Page.OnNextButtonClick := @FilePageNextButtonClick;
end;

有关替代方法,请参阅