Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MDI Child Close Event

Posted on 2003-10-26
8
Medium Priority
?
748 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 600 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

670 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