gpt4 book ai didi

delphi - 如何拦截和抑制 TFrame 子组件的消息?

转载 作者:行者123 更新时间:2023-12-01 23:20:37 27 4
gpt4 key购买 nike

我需要intercept the WM_PASTE message对于放置在 TFrame 的后代类中的 TEdit 组件。

如果不满足条件,我想启动粘贴操作。

有没有办法在帧级别做到这一点? (我的意思是,没有声明 TEdit 的后代)

最佳答案

Is there a way to do this at the frame level? (I mean, without declaring a TEdit's descendant)

WM_PASTE直接发送至TEdit窗口,TFrame永远不会看到它,所以您必须子类化 TEdit直接拦截消息。您可以:

  • TFrame将处理程序分配给 TEditWindowProc属性(property)。如果您只有几个TEdit,这是一个简单的方法。 s 到子类,但越多就越复杂 TEdit您想要子类化:

    type
    TMyFrame = class(TFrame)
    Edit1: TEdit;
    ...
    procedure FrameCreate(Sender: TObject);
    ...
    private
    PrevWndProc: TWndMethod;
    procedure EditWndProc(var Message: TMessage);
    ...
    end;

    procedure TMyFrame.FrameCreate(Sender: TObject);
    begin
    PrevWndProc := Edit1.WindowProc;
    Edit1.WindowProc := EditWndProc;
    ...
    end;

    procedure TMyFrame.EditWndProc(var Message: TMessage);
    begin
    if Message.Msg = WM_PASTE then
    begin
    if SomeCondition then
    Exit;
    end;
    PrevWndProc(Message);
    end;
  • 编写并安装一个源自 TEdit 的新组件,类似于 TMemo example you presented .

  • 定义一个仅位于 TFrame 本地的插入器类。的单位,位于 TFrame 上方类声明,它将拦截 WM_PASTE对于每个TEdit在框架上:

    type
    TEdit = class(Vcl.StdCtrls.TEdit)
    procedure WMPaste(var Message: TMessage); message WM_PASTE;
    end;

    TMyFrame = class(TFrame)
    Edit1: TEdit;
    Edit2: TEdit;
    ...
    end;

    procedure TEdit.WMPaste(var Message: TMessage);
    begin
    if not SomeCondition then
    inherited;
    end;

关于delphi - 如何拦截和抑制 TFrame 子组件的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49304718/

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