Is it possible to allow a user to skip a TInputDirWizardPage in Inno Setup?

泄露秘密 提交于 2019-12-01 05:58:53

Unfortunately no. This is hardcoded in the TInputDirWizardPage.NextButtonClick method, which internally validates all the edit boxes by calling ValidateCustomDirEdit function, which doesn't care if the edit has been left intentionally empty; it just checks if it contains a valid directory path. Or, in other words, the TInputDirWizardPage fields are not optional, they must contain valid paths at this time.

Well, I don't feel this was an expected behavior. If you compare file and dir input page, they differ. Whilst in the file input page you can leave edit boxes empty, in dir input page you cannot. I think, that would be enough if there would be a check if the edit box is not empty and only if it's not, validate its content. You would be able to check whether the edit is empty by yourself (if you'd require mandatory field), and stop the user on that page, but you are not able to suppress that validation if the edit is empty.

In your situation I would consider using TInputFileWizardPage as you were talking about a file input, or creating your own directory input page.

PLopes

As TLama said, there's no way to NOT force validation, it's hardcoded. But that doesn't mean we can't hack the hell out of it!!!

In the example below we override the form NextButton click and if the directory is empty we simply put a value to pass the validation, after that we can clear the directory.

var
  InputDirPage: TInputDirWizardPage;
  Old_WizardForm_NextButton_OnClick: TNotifyEvent;

procedure WizardForm_NextButton_OnClick(Sender: TObject);
var
    IsDirEmpty: Boolean;
begin
    if (WizardForm.CurPageID = InputDirPage.ID) and (InputDirPage.Values[0] = '') then
    begin
        IsDirEmpty := True;
        InputDirPage.Values[0] := WinDir; { Force value to pass validation }
    end;

    Old_WizardForm_NextButton_OnClick(Sender);

    if IsDirEmpty then
        InputDirPage.Values[0] := '';
end;

procedure InitializeWizard();
begin
    InputDirPage := CreateInputDirPage(
        wpWelcome,      { AfterID }
        'ACaption',
        'ADescription',
        'ASubCaption',
        False,          { AAppendDir }
        ''              { ANewFolderName }
    );  

    InputDirPage.Add('doc dir:');

    { override wizard NextButton click }
    Old_WizardForm_NextButton_OnClick := WizardForm.NextButton.OnClick;
    WizardForm.NextButton.OnClick := @WizardForm_NextButton_OnClick;
end;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!