![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
Q: Force an MDI child to close rather than minimizingAnswer:When you close an MDI child, you may notice that the child form minimizes rather than actually closing. TCustomForm::Close explains what is going on. void __fastcall TCustomForm::Close() { ... if(FormStyle == fsMDIChild) { if BorderIcons.Contains(biMinimize)) CloseAction = caMinimize else CloseAction = caNone } ... if (FOnClose) FOnClose(this, CloseAction); ... } CloseAction is an enumerated variable that tells TForm how you want the form to close. Closing can mean several different things. You may want to hide the form, but keep the form object intact for later user. You may want to completely destroy the window and the form object, or you may want to do nothing at all. CloseAction controls how the form will respond to the close command. The possible values are listed in FORMS.HPP. enum TCloseAction { caNone, caHide, caFree, caMinimize }; For forms that are not MDI children, CloseAction is initialized to caHide. Notice that TCustomForm::Close sets CloseAction to caMinimize if the MDI child form has a minimize button in its title bar. MDI children cannot be hidden (a restriction imposed by Windows). The VCL minimizes the form to circumvent the restriction. If you want to close the MDI child instead of minimizing it, write an OnClose handler for the MDI child that sets CloseAction to caFree. The VCL passes the CloseAction variable to your OnClose handler so you can have the last word in how the VCL should react. The code below demonstrates what to do. void __fastcall TMDIChild::FormClose(TObject *Sender, TCloseAction &Action) { Action = caFree; } Note: Setting CloseAction to caFree forces the VCL to destroy the MDI child window and free the form object associated with the child window. Since the form is being destroyed, don't dereference the MDI child's form pointer after you close the window. Also, don't attempt to delete the pointer a second time. | ||||||
All rights reserved. |