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

时间:2019-05-22 19:48:41

标签: inno-setup pascalscript

我设法获得一个基本脚本来显示向导(使用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;

1 个答案:

答案 0 :(得分:1)

您可以使用自定义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;

有关其他方法,请参见Inno Setup Disable Next button when input is not valid