How can I stop a repeating loop in the middle of execution with pressing some button? The program only writes one letter into an edit box and then waits some given time, writes another letter and so on in a specified order, the pauses are made using sysutils.sleep
.
Example:
procedure TForm1.Button4Click(Sender: TObject);
var
j: integer;
begin
edit1.Text:='a';
edit1.Text:='a';
sysutils.Sleep(l*20);
edit1.Text:='b';
edit1.text:='3';
sysutils.sleep(l*20);
j:= 1 ;
repeat
edit1.Text:='1';
sysutils.sleep(l*2);
edit1.Text:='0';
edit1.text:='2';
sysutils.sleep(l*2);
edit1.Text:='3';
edit1.text:='4';
sysutils.sleep(l*2);
edit1.Text:='5';
sysutils.sleep(l*2);
j:= j + 1;
until j = 5;
end;
What I need: I press one button and it writes those letters, then whenever I press some other button, it stops the procedure and jumps to the other button procedures.
I know this is possible since a lot of apps can do a loop until you press something and stop a loop when you press a button, but I have no idea how to do this. Currently, the app freezes until it finishes the loop.