我没写过MDI程序,不过我有个猜想。因为每个控件生成和释放都会触发
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
所以,如果MDI窗体的Owner都是MainForm,可以在MainForm里写这个函数。
如果Operation是opInsert就是创建,opRemove就是释放。然后判断AComponent是否是TForm,且FormStyle是否是fsMDIForm。
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
所以,如果MDI窗体的Owner都是MainForm,可以在MainForm里写这个函数。
如果Operation是opInsert就是创建,opRemove就是释放。然后判断AComponent是否是TForm,且FormStyle是否是fsMDIForm。
按你的方法做后,Free窗体时能相应,但create窗体时无法相应,不知为什么?请赐教.
代码如下:
if (acomponent is Tform)and(Tform(Acomponent).formStyle=fsMDIChild) then
begin
if operation=opInsert then
showmessage('create')
else if operation=opRemove then
showmessage('free');
end;
WM_Create, WM_Close, WM_Destroy
在mdi中子窗体创建释放时,这些消息在主窗体根本截不到.
yourMDIForm := TMDIForm.Create(Application.MainForm) // CReate里跟的参数必须是写Notification函数的窗体的实例