在 InputFilePage (CreateInputFilePage) 上未选择文件时如何禁用 NextButton?
How to disable NextButton when file is not selected on InputFilePage (CreateInputFilePage)?
我的 Inno Setup 程序有一个自定义 "input file page",它是使用 CreateInputFilePage
创建的。
在用户正确选择文件路径之前,如何禁用此页面中的 NextButton
?
换句话说,我需要使 NextButton
在文件选择表单为空时不可点击,而在文件选择表单已填写时可点击。
谢谢。
最简单的方法是使用NextButtonClick
验证输入并在验证失败时显示错误消息。
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;
如果你真的想在输入变化时更新"Next"按钮状态,那就有点复杂了:
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;
我的 Inno Setup 程序有一个自定义 "input file page",它是使用 CreateInputFilePage
创建的。
在用户正确选择文件路径之前,如何禁用此页面中的 NextButton
?
换句话说,我需要使 NextButton
在文件选择表单为空时不可点击,而在文件选择表单已填写时可点击。
谢谢。
最简单的方法是使用NextButtonClick
验证输入并在验证失败时显示错误消息。
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;
如果你真的想在输入变化时更新"Next"按钮状态,那就有点复杂了:
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;