Question

I have a standard Find Dialog:

enter image description here

My program can process some very large files, and finding text in such files may take 10 or 20 seconds or more. So after the "Find Next" button is pressed, I change the cursor to an hourglass. I change it back to the standard pointer after the text is either found or not found.

My problem is that the user may decide to cancel the search and decide to do so by pressing the Cancel button. The Cancel button then closes the dialog but the search continues within my FindDialogFind routine until the text is either found or not found.

I've put a breakpoint upon exit from the FindDialog.exe, but it is not reached until the FindDialogFind is completed.

Is there any way I can capture the fact that the Cancel button has been pressed which will allow me to break the FindDialogFind loop, or maybe is there some better way to stop the search when the Cancel button is pressed?

Was it helpful?

Solution

In the OnCloseevent of the TFindDialog component, set a boolean variable, FAbortSearch. Check this var often in your search routine, and abort if set.

OTHER TIPS

Move the searching logic into a worker thread that you launch whenever the Next button is pressed. When the dialog is closed, you can terminate the thread if it is still running.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top