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

2024-05-14

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

您可以使用OnNextButtonClick您定制的事件进行验证:

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;

对于替代方法,请参阅当输入无效时,Inno Setup 禁用“下一步”按钮 https://stackoverflow.com/q/43738431/850848.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Inno Setup 中单击“下一步”按钮时验证自定义页面上的数据 的相关文章

随机推荐