【发布时间】:2017-05-09 09:14:44
【问题描述】:
我喜欢“覆盖” TWinControl.CNKeyDown,将 Enter 键用作 Tab,而不修改原始 VCL 源。 我也这样做,使用 SetFocus,witch 效果很好。
帮助器类型声明为:
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) 在其中放置了一个叉号。
谁能给我一些指导?
【问题讨论】:
-
您的类需要从 TWinControl 继承并用您想要的行为覆盖它。关于调试断点,您需要为您的项目启用调试 dcu - 请参阅调试部分的docwiki.embarcadero.com/RADStudio/Berlin/en/Compiling
-
它只有在使用助手时才有效,如果我声明像 TWinControlEx = class(TWinControl) 这样的类,那么什么都不会发生,并且调用了更新的函数。我也启用了调试 dcus,但仍然无法调试
-
这都是错误的。通过 WindowProc 属性进行子类化。
标签: delphi