Solved

MDI Child Close Event

Posted on 2003-10-26
8
730 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
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 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 351
Delphi TcxGrid group footer summary 3 354
can't find the executable in Simulator 1 112
Delphi...Split view - idea? 1 114
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

735 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