如果InputQuery为false,则取消过程的其余部分 [英] Cancelling the rest of a procedure if InputQuery is false

查看:67
本文介绍了如果InputQuery为false,则取消过程的其余部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

procedure TForm1.Button2Click(Sender: TObject);
var
  Button: TButton;
  Example : String;

begin

  if {Example = ''} InputQuery('Put a question/request here', Example) then
  Repeat                                                           

    InputQuery('Put a question/request here', Example);

if InputQuery = False then
 Abort
 else
  Until Example <> ''; //or InputBox.


  Button := TButton.Create(self);
  Button.Parent := self;
  //Button properties go here
  Button.Caption := (Example);
  //Any procedures can go here

end;

即使用户按下取消",重复循环后该过程仍将继续.我已经尝试过使用CancelCreateButton标签(如果InputQuery = False)使用GoTo函数,但是我只是遇到错误(所以我删除了一些代码).

This procedure continues after the repeat loop even if the user presses cancel. I've tried using the GoTo function using the CancelCreateButton label if InputQuery = False but I just get errors(so i removed some of the code).

我如何做到这一点,以便如果用户在输入查询上单击取消",它将取消该过程并且不创建按钮?

How can i make it so that if the user clicks cancel on the inputquery it cancels the procedure and doesn't create a button?

推荐答案

如果按下输入查询表单的 Cancel 按钮,则对InputQuery的调用将返回False.在这种情况下,您应该调用Abort(静默异常)来跳过事件处理程序的其余部分.

If the Cancel button of the input query form is pressed, then the call to InputQuery returns False. In that scenario you should call Abort, the silent exception, to skip the rest of the event handler.

if not InputQuery(...) then
  Abort;

如果您想循环执行验证,则如下所示:

If you want to perform validation in a loop then that would look like this:

repeat
  if not InputQuery(..., Name) then
    Abort;
until NameIsValid(Name);

这篇关于如果InputQuery为false,则取消过程的其余部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆