且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Delphi:在运行时释放动态控件

更新时间:2023-12-06 15:01:46

通常,您不应该破坏控件在该控件的事件处理程序中。

In general you should not destroy a control in an event-handler of that control.

但是由于您的函数是普通的非虚拟消息处理程序,因此从未从该控件的内部代码中调用过,所以您应该没事。从样式的角度来看,我不太喜欢,但我认为您的用例还可以。

But since your function is a plain non virtual message handler which is never called from internal code in that control you should be ok. I don't like too too much from a style point of view, but I think it's ok for your use-case.

但是自定义消息可能更简洁。

But a custom message might be cleaner.


在发布CM_RELEASE之后,不可能再将另一个WM_KEY *或类似的消息都准备好了吗?

Would it not be possible that after the CM_RELEASE was posted, another WM_KEY* or similar message could all ready have been posted to the message queue?

如果队列中的消息会引起严重的问题,则由于无法从其他线程和应用程序中发布消息,因此您永远无法安全地销毁控件。只要确保您的应用程序的正确功能不取决于每种情况下处理的那些消息即可。

If messages in queue would cause big problems you could never safely destroy a control since messages can be posted from other threads and applications. Just make sure the correct functioning of your application doesn't depends on those messages being handles in every case.