Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
Delphi-BCB
VCL
8-Byte Alignment
Action Classes
Additional Controls
Core VCL Classes
DFM to TEXT
Dialog Controls
Docking
Drag/Drop
Emulation Classes
Exceptions
Gestures
Graphics
MAPI Support
MDI Support
Multi-Monitor Support
OnGesture event
Printing
Property/Type Editors
Registry / INI Objects
Ribbon Controls
Sample Controls
Services
Standard Controls
Styles
System Controls
Thread support
Touch Controls
Type Info
Win 3.1 Controls
Win 32 Controls
You are not logged in.
Help
Print
Public Report
Report From:
Delphi-BCB/VCL/MDI Support
[ Add a report in this area ]
Report #:
66204
Status:
Reported
Closing mainform, the childs OnClose isn't called
Project:
Delphi
Build #:
11.0.2902.1047
Version:
11.2
Submitted By:
Henrik R. Carlsen
Report Type:
Minor failure / Design problem
Date Reported:
8/29/2008 12:43:32 AM
Severity:
Commonly encountered problem
Last Updated:
8/29/2008 12:46:53 AM
Platform:
All platforms
Internal Tracking #:
Resolution:
None
Resolved in Build:
:
None
Duplicate of:
None
Voting and Rating
Overall Rating:
No Ratings Yet
0.00 out of 5
Total Votes:
None
Description
The attached example is an MDI-application with one child. The child has two events, OnClose and OnDestroy. The OnClose sets Action = caFree.
Opening the child and closing it again, calls the OnClose, then the OnDestroy event.
Same scenario, one child-form open. If I try to close the MDIForm hoping it'll rid the child properly, only the OnDestroy is called. There's no telling that the child form is to free itself.
If I debug it seems that the Application.MainForm is nil before the child is gone. It therefore raises this exception.
procedure TCustomForm.CreateWindowHandle(const Params: TCreateParams);
var
CreateStruct: TMDICreateStruct;
NewParams: TCreateParams;
begin
if (FormStyle = fsMDIChild) and not (csDesigning in ComponentState) then
begin
if (Application.MainForm = nil) or
(Application.MainForm.ClientHandle = 0) then
raise EInvalidOperation.Create(SNoMDIForm); // 'ere!
Steps to Reproduce:
See attachment
Workarounds
Main form OnClose event:
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
var
i: integer;
begin
for i := MDIChildCount - 1 downto 0 do
MDIChildren[i].Close;
end;
Attachment
66204.zip
Comments
Lucian Radulescu at 9/4/2008 12:58:14 PM
-
It works like this since day Delphi 1 - so, I don't think a bit it is going to change.
I too had this issues in MDI apps and what I learned is that you should not rely at all on what VCL does. What I do is override CloseQuery in my mainforms with code like this:
function TWILLMainForm.CloseQuery: Boolean;
var
I: Integer;
begin
if MDIChildCount <> 0 then
repeat
I := MDIChildCount;
SendMessage(ActiveMdiChild.Handle, WM_CLOSE, 0, 0);
Application.ProcessMessages;
until (MDIChildCount = 0) or (I = MDIChildCount);
Result := (MDIChildCount = 0) and inherited CloseQuery;
end;
I don't like it that I have to call Application.ProcessMessages in that loop, but .... that's the best I could do :-)
BTW, your FormClose does not guarantee all the children are closed. (Overriding) Mainform CloseQuery execution is guaranteed. So your app is still safe up and running if one child does not want to close.
hth
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us