It is a question that I see many times. There is an option to use a global boolean variable set from an OnClick event. Another one, used here, consists on reading the state of the key in the loop, to know if it is or not pressed...
varDelphi tips navigator:
j : integer;
begin
for j:=0 to 9999999 do
begin
Label1.Caption := IntToStr(j) ;
{.... loop main body here ...}
Application.ProcessMessages;
{ESC key stops the loop}
if GetKeyState(VK_Escape) AND 128 = 128 then break;
end;
end;
» How to "HotTrack" any control
« Scrolling Memo text from code

