gpt4 book ai didi

delphi - 输入框中的取消按钮未关闭

转载 作者:行者123 更新时间:2023-12-02 09:19:44 24 4
gpt4 key购买 nike

我通过单击按钮使用输入框来存储值并对其执行一些验证。我的问题是单击取消按钮时它不会关闭,而是弹出空检查信息。任何帮助表示赞赏。谢谢

对于空检查,它会弹出“请输入一个值并重试”。
问题是,即使我单击“取消”,它也会显示相同的消息,例如“请输入一个值并重试”,当我不提供任何值并单击“确定”时,它会显示相同的消息“请输入一个值并重试”

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是空字符串。空字符串也是当用户按下“取消”按钮时函数返回的值。

If the user presses OK, the default or user entered data is stored in the return string, otherwise an empty string is returned.

在这种情况下,您无法确定该值来自何处(来自“确定”或来自“取消”)。

我建议使用InputQuery而不是输入框。

类似于:

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 <> ''));

关于delphi - 输入框中的取消按钮未关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32476597/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com