Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI children 2

Status
Not open for further replies.

sggaunt

Programmer
Jul 4, 2001
8,620
0
0
GB
Hi

What I need to do is make sure that all text in child windows is saved, if the user shuts down the Application.
Delphi help suggests using onclosequery to do this.
so we must attempt to close all the childern to trigger this event.
If one of the child window is active when selecting Exit.
It must then shut down all the others. this is why I had a looping structure in the main unit to close all the children 'cafree' is set true in all cases.
But I still get an exception, I have always assumed that this because the child form calls a main form procedure and this then returns to code that has been freed.

Steve.
 
Steve


What you could do is write the code to check for saving in the MMDIChild

Code:
procedure TMDIChild.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if MessageDlg('Save application ?', mtConfirmation,
    [mbYes, mbNo], 0) = mrYes then
  begin
    doMySaveFunction();
    Action := caFree
  end
  else
    Action := caFree;
end;

THEN

In the mainfrom.onClose use

Code:
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var
  I: Integer;
begin
  with MainForm do
    for I := MDIChildCount-1 downto 0 do
      MDIChildren[I].Close;
end;

This will make sure that the onClose is called for each child allowing you to handle the clean up..


X-)
Billy H

bhogar@acxiom.co.uk
 
Yes I have been doing all that.
But I think the problem may be related to the way my menus are set up. I have been calling the main form exit procedure from the child form menus, this is because I can't seem to find a way to keep the main form 'File/Exit' Menu item when the menus are merged.

Steve..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top