On the form of two buttons - Button1 and Button2. In Button1, when pressed, a loop is performed, reading a text, processing and saving the result.

How you can implement: Stop the loop when you click the Button2 button:

var f1,f2:TextFile; s:string; i:integer; ................................... ///////////////Я так поняла где то вот тут нужно вставить условие ? while not Eof(f1) do begin Application.ProcessMessages; /////// что бы программа не зависала Readln(f1,s); s := AnsiUpperCase(s); Writeln(f2,s); end; CloseFile(f1); CloseFile(f2); end; 
  • @Anton Shchyrov, I am grateful for the answer, but the question is: Why is Application.ProcessMessages a harmful and dangerous function? - Tatiana

1 answer 1

  1. Throw Application.ProcessMessages as one of the most harmful and dangerous functions.
  2. Move the execution of Button1Click code to a separate thread
  3. Cycle condition

     while not Eof(f1) do begin 

    replaced by

     while not Terminated and not Eof(f1) do begin 
  4. In the Button2Click handler Button2Click write MyThread.Terminate;
  • I am grateful for the answer, but the question is: Why is Application.ProcessMessages a harmful and dangerous function? - Tatiana
  • 3
    Harmful, because it disaccreats to think and provokes to do as quickly, and not as more correctly (the second such function is Sleep except for debugging, and in exceptional cases). And dangerous, because during the execution of the cycle, the form is active and it can, for example, close or press the start button again. What happens to your cycle then? - Anton Shchyrov 1:43 pm
  • Anton Shchyrov, practical advice. I will consider your information. - Tatiana