如何中断 Delphi 中的查找对话框?
我有一个标准的查找对话框:
我的程序可以处理一些非常大的文件,并在这些文件中查找文本可能需要 10 或 20 秒或更长时间。因此,按下“查找下一个”按钮后,我将光标更改为沙漏。在找到或未找到文本后,我将其更改回标准指针。
我的问题是用户可能决定取消搜索并决定通过按“取消”按钮来执行此操作。然后,“取消”按钮将关闭该对话框,但搜索将在 FindDialogFind 例程中继续进行,直到找到或未找到文本。
我在退出 FindDialog.exe 时设置了断点,但直到 FindDialogFind 完成后才到达断点。
有什么方法可以捕获已按下“取消”按钮的事实,这将允许我打破 FindDialogFind 循环,或者也许有一些更好的方法可以在按下“取消”按钮时停止搜索?
I have a standard Find Dialog:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
TFindDialog
组件的OnClose
事件中,设置一个布尔变量FAbortSearch
。在您的搜索例程中经常检查此变量,如果设置则中止。
In the
OnClose
event of theTFindDialog
component, set a boolean variable,FAbortSearch
.Check this var often in your search routine, and abort if set.
将搜索逻辑移至工作线程中,每当按下
Next
按钮时都会启动该线程。当对话框关闭时,如果线程仍在运行,您可以终止该线程。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.