Solved

MDI Child Close Event

Posted on 2003-10-26
8
739 Views
Last Modified: 2010-04-16
I have an MDI application. I want to know if there is an event for child close.
i've tried :

  if Message.Msg=WM_MDIDESTROY then begin
     ShowMessage('Child closed');
  end else inherited WndProc(Message);

but it does not work. Can anyone tell me why?
0
Comment
Question by:ntony
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9625417
why not use the onClose.event of your MDIChild?
0
 
LVL 1

Author Comment

by:ntony
ID: 9625523
I have a list with child window so i need to delete the child when it will be closed.
0
 

Expert Comment

by:huiyue
ID: 9625551

Is the childform really closed in your program.
You can try to write some codes in the two event:OnClose,OnDestroy.
Just like showmessage('c') in onclose;showmessage('d') in onDestroy.
You will find that when you close the Childform,only show "c" ;
When you add "action :=caFree" in OnClose,you will see "d";
So...maybe you will find the right answer.

I guess but not test the following code;
if Message.Msg=WM_Close then begin
     ShowMessage('Child closed');
  end else inherited WndProc(Message);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9625554
you could notify the mainform in the onClose-event of your MDIChilds instead

may this possible for you?
0
 
LVL 1

Author Comment

by:ntony
ID: 9625581

huiyue i've used caFree on the child form.

Kretzschmar - i need a simple solution
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9625614
how shows your list?
by classname or by formname?
0
 
LVL 1

Author Comment

by:ntony
ID: 9625624
is't a stringlist with objects TForm
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 150 total points
ID: 9625674
well a sceleton

the main:

unit MDIChild_Notifys_Main_Main_u;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,
  MDIChild_Notifys_Main_Child;  //uses the childUnit in the Interfacepart

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FFormList : TstringList;
  public
    procedure RemoveFromList(AForm : TForm);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RemoveFromList(AForm : TForm);
var i : integer;
begin
  i := FFormList.IndexOfObject(AForm);
  if i > -1 then
    FFormList.Delete(i);
  ShowMessage('Child removed.'+#10+'Remaining Childs: '+inttostr(FFormList.Count));
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  FFormList := TStringList.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FFormList.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var f : Tform2;
begin
  f := Tform2.Create(self);
  FFormList.AddObject('AChild',f);
end;

end.

-----------------------

the child:

unit MDIChild_Notifys_Main_Child;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm2 = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

uses
  MDIChild_Notifys_Main_Main_u;  //important-> uses in the implementation

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  TForm1(Application.MainForm).RemoveFromList(self);
  action := caFree;
end;

end.

----

meikl ;-)

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question