delphi - Delphi 的 KeyPreview 是如何工作的?

标签 delphi

我和一位同事正在争论哪种方式对系统资源的负担较小。 (注意:这不是我想要答案的问题。相反,标题和下面粗体的行是我寻求答案的问题。)

1. Using KeyPreview to get the keypresses on a form.

2. Using defining an OnMessage procedure and handling it there.

乍一看,KeyPreview 似乎不会造成系统负担,因为定义 OnMessage 过程会导致我们的程序检查传入的每条消息。请注意,我们不关心的消息会导致它在第一个 if 时跳出陈述。最坏的情况是我们会对每条消息执行一个 if 语句。

但是我们想知道 Delphi 如何处理 KeyPreview 属性...我们想知道 Delphi 是否在内部定义了自己的 OnMessage 并查看消息,然后触发与按键相关的事件。

如果是这种情况,那么两种方法是否大致相同?

最佳答案

正如其他人已经说过的 - 可能没有明显的差异。

我只是想指出Peter Below关于该主题的一篇优秀文章:A Key's Odyssey archive

This article describes the key message processing as implemented in Delphi 2007 for Win32 VCL forms applications. A few things have changed in this area compared with Delphi 7, but these are mostly additions that I will highlight when we get to them. Most of this code has survived basically unchanged since the times of Delphi 1, a tribute to the robustness of the design. If you are in a hurry or not interested in all the details you can refer to the outline in the summary for a condensed overview.

关于delphi - Delphi 的 KeyPreview 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6509242/

相关文章:

delphi - 如何在运行时将图像分配给 TImage 控件

delphi - 如何导出Delphi 2010的代码格式化程序设置?

delphi - 使用 indy/delphi 组件通过 https 发布文件

delphi - 只允许字符串中的某些字符

delphi - 不对 .dproj 进行版本控制的优点

delphi - 在 Delphi 中迭代枚举中的项目

string - Delphi中大字符串的安全连接

delphi - 为自定义组件创建样式的正确方法

delphi - Delphi Win32 中的类帮助器和字符串

Delphi XE 中 TClientDataSet(CDS 文件)的 SQL 查询?