Question and Answer Database FAQ2301C.txt How can I abort a lengthy operation? Category :IDE Platform :All Product :C++Builder 3.x Question: How can I abort a lengthy operation? Answer: Create a global boolean variable to indicate if a abort button has been pressed. Call Application->ProcessMessages() to allow other events (the changing of the abort flag) in your application to process. Check the value of the global boolean during your lengthy event, and break out if it returns true. Calling Application->ProcessMessages() will also allow other applications to process, allowing for a smooth flow of system events. Note that you must be careful to control re-enterance, since other controls in your application may receive messages as well. Example: void __fastcall TForm1::Button1Click(TObject *Sender) { int i; bAbort = false; for(i=0; i<1000000; i++) { Application->ProcessMessages(); if(bAbort == true) break; } if(bAbort == true) ShowMessage("Operation Aborted"); else ShowMessage("Operation Successful"); } void __fastcall TForm1::Button2Click(TObject *Sender) { bAbort = true; } 7/2/98 10:32:32 AM
Last Modified: 01-SEP-99