在Inno Setup中单击“下一步"按钮时,验证自定义页面上的数据 [英] Validate data on custom page when Next button is clicked in Inno Setup

查看:449
本文介绍了在Inno Setup中单击“下一步"按钮时,验证自定义页面上的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have managed to get a basic script working to display a wizard (using CreateInputFilePage) for a user to identify a file location that I use to update some settings in an XML file. However, I would like to perform some basic checking of the input to the file selected rather than simply accepting whatever the user provides. For example displaying a message box if the user attempts to press **Next"* when the content is invalid. I am not entirely sure how to handle events arising from the wizard and how to apply any kind of validation rules to the data before proceeding to the next task. Currently, I have defined a simple InitializeWizard procedure.

[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文件中的某些设置

I then recover the file name and location when the CurStepChanged event is triggered and use this to update the some settings in an XML file

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;

推荐答案

您可以使用自定义

You can use OnNextButtonClick event of your custom TWizardPage to do your validation:

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按钮.

这篇关于在Inno Setup中单击“下一步"按钮时,验证自定义页面上的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆