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;
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?
If the Cancel button of the input query form is pressed, then the call to
InputQuery
returnsFalse
. In that scenario you should callAbort
, the silent exception, to skip the rest of the event handler.If you want to perform validation in a loop then that would look like this:
You can also use the
Exit
functionYou have too many calls to InputQuery, three when you only need one; it is better to capture the result of InputQuery to a Boolean variable and use that for execution flow control. Try something like this instead:
Assuming that does what you intend for a single student, you can reinstate the
repeat ... until
to get the behaviour you need.