I would like to add a button to my form with which a running process (loop which runs several thousand times) can be terminated if the user wishes to stop the process for any reason or load another file.
The program has a part which performs an interpolation for multiple cases and creates and saves a text file for each case. Once the process is launched (this is done by pressing a button after the necessary files have been loaded), it starts running and cannot be stopped until it is completed. The duration of this process could be anything between minutes and hours depending on the size of certain files.
I have copied a code snippet from the part which is called when the button is pressed (changed names and certain parts and ommitted what follows the first if block as it is irrelevant here).
void __fastcall TMapperForm::bt_InterpolationClick(TObject *Sender)
{
int i;
if(someflagused == true)
{
different_cases_total = 0;
for(i=0; i<something_counter; i++)
{
CleanStuff();
FunctionReadingFiles(list_of_stuff->Items->Strings[i]);
InterpolatingFunction();
different_cases_total+= no_cases;
}
}
}
As written above, I would like to create another button which can kill/terminate the process. My main problem is that when the program runs, it freezes and I see no way to interrupt the loop.
Is there any way to add a button which remains active even when the loop is running and can terminate the process when clicked?