Delphi:子类化和恢复控件的适当时间?
开始对控件进行子类化的正确地点/时间是什么?
什么时候恢复原来的窗口进程合适?
现在我在表单创建期间进行子类化:
procedure TForm1.FormCreate(Sender: TObject);
begin
FOldPanel1WindowProc := Panel1.WindowProc;
Panel1.WindowProc := Panel1WindowProc;
end;
并且在表单销毁期间恢复子类化:
procedure TForm1.FormDestroy(Sender: TObject);
begin
Panel1.WindowProc := FOldPanel1WindowProc;
end;
只要我不使用ThemeManager,其子类控制自身。一旦尝试子类化 ThemeManager 也子类化的控件,我就会遇到非常讨厌的错误。
我认为这是因为我不应该在创建期间启动子类并在销毁期间恢复它。那么,在 Delphi 中子类化和取消子类化控件的正确记录时间是多少?
What is the correct place/time to start subclassing a control?
What is the proper time to restore the original window proc?
Right now i subclass during form creation:
procedure TForm1.FormCreate(Sender: TObject);
begin
FOldPanel1WindowProc := Panel1.WindowProc;
Panel1.WindowProc := Panel1WindowProc;
end;
and i restore the subclassing during form destruction:
procedure TForm1.FormDestroy(Sender: TObject);
begin
Panel1.WindowProc := FOldPanel1WindowProc;
end;
This works fine, as long as i don't use ThemeManager, which subclasses controls itself. As soon as a try to subclass a control that ThemeManager also sub-classes, i get very nasty errors.
i assume it's becuase i should not start the subclass during Create and restore it during Destroy. So what is the properly documented time to subclass and unsubclass a control in Delphi?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题尚不清楚,但我假设您在尝试在表单的 OnDestroy 事件处理程序中恢复旧窗口过程时遇到错误。
在处理控件的 WM_DESTROY 时,ThemeManager 会恢复其子类化。因此,您可能必须执行相同的操作:在新窗口过程中监视
WM_DESTROY
并首先恢复子类化,然后调用旧窗口过程(并让 ThemeManager 执行相同的操作)。我还没有测试过这个,但我认为它应该有效。
It's not clear from your question but I assume you get the errors when you're trying to restore the old window procedure in the form's OnDestroy event handler.
ThemeManager reverts its subclassing when processing
WM_DESTROY
for a control. Therefore you probably have to do the same: watch forWM_DESTROY
in your new window procedure and revert your subclassing first, then call the old window procedure (and let ThemeManager do the same thing).I haven't tested this but I think it should work.