Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MDI Child Close Event

Posted on 2003-10-26
8
Medium Priority
?
754 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
  • 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
Industry Leaders: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

824 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