gpt4 book ai didi

delphi - 从子组件处理父WndProc

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

我正在研究一个新的组件,我想处理所有父消息。

Type
TMyComponent= class(TComponent)
//Bla bla
/..
//.
published
property Parent: TWinControl read FParent write SetParent;

end;


我想访问父级WndProc(处理所有父级消息)。有什么办法可以从我的TMyComponent处理Parent WndProc?

最佳答案

像这样:

type
TMyComponent = class(TComponent)
private
FParent: TWinControl;
FParentWindowProc: TWndMethod;
procedure WindowProc(var Message: TMessage);
procedure SetParent(Value: TWinControl);
published
property Parent: TWinControl read FParent write SetParent;
end;

procedure TMyComponent.SetParent(Value: TWinControl);
begin
if Value=FParent then
exit;

if Assigned(FParent) then
FParent.WindowProc := FParentWindowProc;
FParentWindowProc := nil;

FParent := Value;

if Assigned(FParent) then
begin
FParentWindowProc := FParent.WindowProc;
FParent.WindowProc := WindowProc;
end;
end;

procedure TMyComponent.WindowProc(var Message: TMessage);
begin
// do whatever we want with the message
FParentWindowProc(Message);// delegate to parent's window procedure
end;

关于delphi - 从子组件处理父WndProc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13892991/

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