Solved

MDI Child Close Event

Posted on 2003-10-26
8
723 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now