gpt4 book ai didi

delphi - TWinControl 的助手

转载 作者:行者123 更新时间:2023-12-03 18:18:03 27 4
gpt4 key购买 nike

我喜欢“覆盖”TWinControl.CNKeyDown,将 Enter 键用作 Tab,而不修改原始 VCL 源。我也这样做,使用 SetFocus,效果很好。

辅助类型声明为:

type
TWinControlEx = class helper for TWinControl
private
procedure SetFocus; reintroduce;
procedure CNKeyDown(var Message: TWMKeyDown); reintroduce;
end;

重写的方法如下所示:

if (Message.CharCode = 13) and (Pos('Cr_To_Tab',ImeName)>0) and (Pos('No_Cr_To_Tab',ImeName)=0) then
begin
if not ((GetKeyState(VK_CONTROL) and not $7FFF) <> 0) then
begin
Message.CharCode := 9;
end;
end;
Message.CharCode := 9;
inherited;

但是我的代码运行起来好像还是用原来的版本。另一个令人沮丧的事情是我无法调试问题,因为当我在 CNKeyDown 方法中放置一个断点时,它永远不会停止,并且 IDE (RAD Studio 10.2) 在其中放置了一个叉号。

谁能给我一些指导?

最佳答案

您不能像您尝试的那样使用类助手来重新引入现有方法的新版本。

类助手不是解决方案。您需要改为:

  1. 从所需的原始类派生一个新类,如 TEdit,并覆盖其适用的virtual/dynamic 方法,如 WndProc()KeyDown() 等,然后在运行时创建自定义类的实例而不是原始类。您可以在设计时在 IDE 中安装您的自定义类,也可以将您的类实现为 Interposer,以便它仅在运行时覆盖原始类。参见 Two Approaches to Sub-classing Components Compared了解更多详情。

  2. 根本不要派生新类。只需在运行时子类化原始类的所需对象实例的 WindowProc 属性。然后您可以在他们处理之前处理他们的窗口消息。

关于delphi - TWinControl 的助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43865802/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com