我在这里找到了一个我需要的代码.仅允许在文本框中写入数字.但我仍然想要更多,没有提供“下一步”按钮而没有在此文本框中写入数字.
可以帮我?
procedure NumbersOnly(Sender: TObject; var Key: Char); var S: string; begin S := ('1234567890'#8); if Pos(Key,S) = 0 then Key := #0; end;
解决方法
当用户到达编辑框所在的页面时,您可以在
CurPageChanged
事件中设置要启用或禁用的下一个按钮.除非您需要监视该编辑框的更改,以根据是否在该编辑框中输入了某些内容来启用或禁用下一个按钮.为此,您需要为OnChange事件编写处理程序.这是一个例子:
[Setup] AppName=My Program AppVersion=1.5 DefaultDirName={pf}\My Program [Code] var MyEdit: TNewEdit; MyPage: TWizardPage; procedure MyEditChange(Sender: TObject); begin { enable the next button if the edit Box is not empty; disable otherwise } WizardForm.NextButton.Enabled := MyEdit.Text <> ''; end; procedure MyEditKeyPress(Sender: TObject; var Key: Char); var KeyCode: Integer; begin { allow only numbers } KeyCode := Ord(Key); if not ((KeyCode = 8) or ((KeyCode >= 48) and (KeyCode <= 57))) then Key := #0; end; procedure InitializeWizard; begin MyPage := CreateCustomPage(wpWelcome,'Caption','Description'); MyEdit := TNewEdit.Create(WizardForm); MyEdit.Parent := MyPage.Surface; MyEdit.Left := 0; MyEdit.Top := 0; MyEdit.Width := 150; MyEdit.OnChange := @MyEditChange; MyEdit.OnKeyPress := @MyEditKeyPress; end; procedure CurPageChanged(CurPageID: Integer); begin { if the currently turned wizard page is the one with the edit Box,enable } { the next button if the edit Box is not empty; disable otherwise } if CurPageID = MyPage.ID then WizardForm.NextButton.Enabled := MyEdit.Text <> ''; end;