简体   繁体   English

Delphi框架销毁/隐藏

[英]Delphi Frame Destroy/Hide

HI

I have an application with more than one frame that act as forms. 我有一个具有多个框架的应用程序。

I have temporary files I need to delete when the user moves from a certain frame and I currently delete the file when they press OK or CANCEL. 我有一些临时文件,当用户从某个帧移出时我需要删除这些文件,而当他们按OK或CANCEL时,我目前正在删除该文件。

If they just close the application I also want to delete the temporary files but cannot determine when the frame is destroyed. 如果他们只是关闭应用程序,我也想删除临时文件,但无法确定框架何时被破坏。

Regards, Pieter 问候,彼得

To detect when a frame is destroyed, override its destructor, Destroy . 要检测框架何时被破坏,请覆盖其析构函数Destroy

If overriding the destructor is not appropriate (say, if the files belong to the enclosing form rather than the frame), then you can use component notification . 如果不适合覆盖析构函数(例如,如果文件属于封闭形式而不是框架),则可以使用组件通知 After you create the frame, call its FreeNotification method, passing in a reference to the enclosing form. 创建框架后,调用其FreeNotification方法,并传递对封闭表格的引用。 When the frame is destroyed, it will call the form's Notification method. 当框架被销毁时,它将调用表单的Notification方法。 Override that method in your form, and if the component is the frame, delete the files. 覆盖表单中的该方法,如果组件是框架,则删除文件。 (That method may be called many times in your program, so checking the AComponent parameter is important.) (该方法可能在您的程序中被多次调用,因此检查AComponent参数很重要。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM