如何中断 Delphi 中的查找对话框?

发布于 2024-12-25 12:40:26 字数 444 浏览 5 评论 0原文

我有一个标准的查找对话框:

在此处输入图像描述

我的程序可以处理一些非常大的文件,并在这些文件中查找文本可能需要 10 或 20 秒或更长时间。因此,按下“查找下一个”按钮后,我将光标更改为沙漏。在找到或未找到文本后,我将其更改回标准指针。

我的问题是用户可能决定取消搜索并决定通过按“取消”按钮来执行此操作。然后,“取消”按钮将关闭该对话框,但搜索将在 FindDialogFind 例程中继续进行,直到找到或未找到文本。

我在退出 FindDialog.exe 时设置了断点,但直到 FindDialogFind 完成后才到达断点。

有什么方法可以捕获已按下“取消”按钮的事实,这将允许我打破 FindDialogFind 循环,或者也许有一些更好的方法可以在按下“取消”按钮时停止搜索?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

德意的啸 2025-01-01 12:40:26

TFindDialog 组件的 OnClose 事件中,设置一个布尔变量 FAbortSearch
在您的搜索例程中经常检查此变量,如果设置则中止。

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

走走停停 2025-01-01 12:40:26

将搜索逻辑移至工作线程中,每当按下 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文