输入框中的取消按钮不关闭
Cancel Button in Inputbox doesn't close
我在单击按钮时使用输入框来存储值并对其执行一些验证。我的问题是单击取消按钮时它不会关闭,而是弹出信息以进行空检查。任何帮助表示赞赏。谢谢
对于空检查,它会弹出 "please enter a value and try again"。
问题是,即使我单击取消,它也会显示与 "please enter a value and try again" 相同的消息,而当我不提供任何值并单击确定时,它会显示相同的消息 "please enter a value and try again"
procedure TForm1.Button1Click(Sender: TObject);
var inputValue:string;
begin
repeat
inputValue:=InputBox('Enter a value', 'value','');
if (inputValue<>'') then
begin
if MessageDlg('Do You want to enter this value ' +inputValue+'?',mtInformation,[mbYes,mbNo],0)= mrYes then
MessageDlg('Your Value got stored', mtInformation,[mbOk],0)
end;
until(inputValue='');
repeat
if (inputValue = '') then
MessageDlg('Please Enter a value and try again', mtInformation,[mbOk],0) ;
inputValue:=InputBox('Enter a value', 'value','');
if (inputValue<>'') then
begin
if MessageDlg('Do You want to enter this value ' +inputValue+'?',mtInformation,[mbYes,mbNo],0)= mrYes then
MessageDlg('Your Value got stored', mtInformation,[mbOk],0)
end;
until (inputValue<>'') ;
end;
问题是函数 InputBox 的参数 default
是空字符串。空字符串也是用户按下 "Cancel" 按钮时函数返回的值。
If the user presses OK, the default or user entered data is stored in
the return string, otherwise an empty string is returned.
在这种情况下,您无法确定该值的来源(来自 Ok 或来自 Cancel)。
我建议使用 InputQuery 而不是 InputBox。
类似于:
var
InputValue : string;
CustIsPressOK : boolean;
begin
repeat
CustIsPressOK := InputQuery('Enter a value', 'value',InputValue);
if CustIsPressOK then
begin
if InputValue <> '' then
begin
if MessageDlg('Do You want to enter this value ' +inputValue+'?',mtInformation,[mbYes,mbNo],0)= mrYes then
MessageDlg('Your Value got stored', mtInformation,[mbOk],0);
end
else
begin
//user is pressed OK button but value is empty string
MessageDlg('Please Enter a value and try again', mtInformation,[mbOk],0) ;
end;
end;
until (CustIsPressOK = false) or (CustIsPressOK and (InputValue <> ''));
我在单击按钮时使用输入框来存储值并对其执行一些验证。我的问题是单击取消按钮时它不会关闭,而是弹出信息以进行空检查。任何帮助表示赞赏。谢谢
对于空检查,它会弹出 "please enter a value and try again"。
问题是,即使我单击取消,它也会显示与 "please enter a value and try again" 相同的消息,而当我不提供任何值并单击确定时,它会显示相同的消息 "please enter a value and try again"
procedure TForm1.Button1Click(Sender: TObject);
var inputValue:string;
begin
repeat
inputValue:=InputBox('Enter a value', 'value','');
if (inputValue<>'') then
begin
if MessageDlg('Do You want to enter this value ' +inputValue+'?',mtInformation,[mbYes,mbNo],0)= mrYes then
MessageDlg('Your Value got stored', mtInformation,[mbOk],0)
end;
until(inputValue='');
repeat
if (inputValue = '') then
MessageDlg('Please Enter a value and try again', mtInformation,[mbOk],0) ;
inputValue:=InputBox('Enter a value', 'value','');
if (inputValue<>'') then
begin
if MessageDlg('Do You want to enter this value ' +inputValue+'?',mtInformation,[mbYes,mbNo],0)= mrYes then
MessageDlg('Your Value got stored', mtInformation,[mbOk],0)
end;
until (inputValue<>'') ;
end;
问题是函数 InputBox 的参数 default
是空字符串。空字符串也是用户按下 "Cancel" 按钮时函数返回的值。
If the user presses OK, the default or user entered data is stored in the return string, otherwise an empty string is returned.
在这种情况下,您无法确定该值的来源(来自 Ok 或来自 Cancel)。
我建议使用 InputQuery 而不是 InputBox。
类似于:
var
InputValue : string;
CustIsPressOK : boolean;
begin
repeat
CustIsPressOK := InputQuery('Enter a value', 'value',InputValue);
if CustIsPressOK then
begin
if InputValue <> '' then
begin
if MessageDlg('Do You want to enter this value ' +inputValue+'?',mtInformation,[mbYes,mbNo],0)= mrYes then
MessageDlg('Your Value got stored', mtInformation,[mbOk],0);
end
else
begin
//user is pressed OK button but value is empty string
MessageDlg('Please Enter a value and try again', mtInformation,[mbOk],0) ;
end;
end;
until (CustIsPressOK = false) or (CustIsPressOK and (InputValue <> ''));