How to disable NextButton when file is not selected on InputFilePage (CreateInputFilePage)?

为君一笑 提交于 2019-11-30 16:19:45

问题


My Inno Setup program have a custom "input file page" that was created using CreateInputFilePage.

How can I disable the NextButton in this page until the file path is properly picked by the user?

In other words, I need to make the NextButton unclickable while the file selection form is empty, and clickable when the file selection form is filled.

Thank you.


回答1:


The easiest way is to use NextButtonClick to validate the inputs and display an error message when the validation fails.

var
  FilePage: TInputFileWizardPage;

procedure InitializeWizard();
begin
  FilePage := CreateInputFilePage(wpSelectDir, 'caption', 'description', 'sub caption');
  FilePage.Add('prompt', '*.*', '.dat');
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;

  if (CurPageID = FilePage.ID) and
     (Length(FilePage.Edits[0].Text) = 0) then
  begin
    MsgBox('Please select a file.', mbError, MB_OK);
    WizardForm.ActiveControl := FilePage.Edits[0];
    Result := False;
  end;
end;

If you really want to update the "Next" button state while the input changes, it is a bit more complicated:

procedure FilePageEditChange(Sender: TObject);
begin
  WizardForm.NextButton.Enabled := (Length(TEdit(Sender).Text) > 0);
end;

procedure FilePageActivate(Sender: TWizardPage);
begin
  FilePageEditChange(TInputFileWizardPage(Sender).Edits[0]);
end;

procedure InitializeWizard();
var
  Page: TInputFileWizardPage;
  Edit: TEdit;
begin
  Page := CreateInputFilePage(wpSelectDir, 'caption', 'description', 'sub caption');
  { To update the Next button state when the page is entered }
  Page.OnActivate := @FilePageActivate;

  Edit := Page.Edits[Page.Add('prompt', '*.*', '.dat')];
  { To update the Next button state when the edit contents changes }
  Edit.OnChange := @FilePageEditChange;
end;


来源:https://stackoverflow.com/questions/35837765/how-to-disable-nextbutton-when-file-is-not-selected-on-inputfilepage-createinpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!