- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我喜欢“覆盖”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) 在其中放置了一个叉号。
谁能给我一些指导?
最佳答案
您不能像您尝试的那样使用类助手来重新引入现有方法的新版本。
类助手不是解决方案。您需要改为:
从所需的原始类派生一个新类,如 TEdit
,并覆盖
其适用的virtual
/dynamic
方法,如 WndProc()
、KeyDown()
等,然后在运行时创建自定义类的实例而不是原始类。您可以在设计时在 IDE 中安装您的自定义类,也可以将您的类实现为 Interposer,以便它仅在运行时覆盖原始类。参见 Two Approaches to Sub-classing Components Compared了解更多详情。
根本不要派生新类。只需在运行时子类化原始类的所需对象实例的 WindowProc
属性。然后您可以在他们处理之前处理他们的窗口消息。
关于delphi - TWinControl 的助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43865802/
我喜欢“覆盖”TWinControl.CNKeyDown,将 Enter 键用作 Tab,而不修改原始 VCL 源。我也这样做,使用 SetFocus,效果很好。 辅助类型声明为: type T
如何改 rebase 于 TWinControl 的控件的不透明度?为什么他们不将此功能添加到 TControl/TWinControl 级别(为什么只添加到 TForm)? 最佳答案 控制窗口的不透
我面临着必须拦截和处理 WM_GETOBJECT 的艰巨任务。每当发送到表单上的任何 TWinControl 时都会发送消息。 每个面板 每个嵌套面板 每个编辑框 每个组合框 每个按钮 每个工具栏 每
我想将已发布的属性添加到 TWinControl 中。有没有办法在不需要重新编译基本源代码的情况下做到这一点? 如果没有,有什么方法可以重新编译基本源代码而不用太麻烦? 感谢您的建议... 因新想法而
我正在创建一个 Delphi 服务。有没有办法在服务中使用从 TWinControl 派生的控件?最终,我放置在它上面的控件和任何控件都将保存到位图。但是我尝试的任何操作都会出现“控件没有父窗口”错误
使用伪函数进行子类化: CreateSpecialHandle(TWinControl *Control, const TCreateParams &Params, const AnsiString
谁能告诉我为什么第二次转换在 Delphi 7 中编译失败? var WebBrowser: TWebBrowser; begin WebBrowser := TWebBrowser.Crea
想象一下,您想要分配自己的事件过程: procedure TSuperObject.DoSomething(Sender: TObject; Button: TMouseButton; Shift:
我需要将焦点设置在 TEdit 控件上。通常,我在检查控件是否可以聚焦后使用TWinControl.SetFocus。最近,我注意到TCustomForm类提供了SetFocusedControl函数
我有这个代码: procedure TForm1.FormCreate(Sender: TObject); begin DoSomethingWithCombobox(ComboBox1.Hand
我试图在 TWinControl 中显示自定义提示,但我不知道如何获取它的位置。 使用位置 0,0 在屏幕顶部(窗口外)显示提示,所以我猜它一定是屏幕上控件的位置。 编辑: 我发现 TControl
我有一个高度多线程的 Delphi 6 应用程序。我创建了一个源自 TWinControl 的组件。当我第一次构建它时,我使用了一个隐藏窗口,它是 WndProc 来处理消息,并使用 Allocate
我是一名优秀的程序员,十分优秀!