Solved

catching events from mdi Child window

Posted on 2002-05-27
11
340 Views
Last Modified: 2010-08-05
Hi All,

I have a mdi app with several mdichild forms. On the mdi parent window i have a toolbar with a button that creates the child window and disables the button :

procedure TFrmMain.ToolButton1Click(Sender: TObject);
begin
 FrmCompanySearch := TFrmCompanySearch.Create(Self);
 FrmCompanySearch.Show;
 ToolBar1.Buttons[0].Enabled := false;
end;

The childwindow has his own onclose handler :

procedure TFrmCompanySearch.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Action := caFree;
  FrmCompanySearch := nil;
end;

Now the Question : How do i enable the toolbarbutton after the onclose event. So how can i catch the childwindow on close in my mdi parent form !

I hope that its a bit clear,
Thanks in advance,

Yuri
0
Comment
Question by:muldeyur
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7038551
you could send a wm_user+xxx message to your mainform
and handle the message there,
or
you could access directly the mainform

in your child-closemethod

meikl ;-)
0
 

Author Comment

by:muldeyur
ID: 7038607
how do i access the Mainform directly?
do you have a code example?

regards

Yuri
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 7038626
simplified (from head)

mainform:

type tform1 ....

     public
       Procedure Handle_ChildClose(AChild : TForm);
    ....

implementation

procedure tform1.Handle_ChildClose(AChild : TForm);
begin
  if (aform is TFrmCompanySearch) then
    ToolBar1.Buttons[0].Enabled := true;
  //..maybe more childclasses to handle
end;

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

childform

...

implementation
uses mainformunit; //!include this with your real unit name

....
procedure TFrmCompanySearch.FormClose(Sender: TObject;
 var Action: TCloseAction);
begin
 Action := caFree;
 FrmCompanySearch := nil;
 mainformname.handle_ChildClose(self);
end;

------

hope this helps

meikl ;-)


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: 7038635
oops there is a typo

this line
if (aform is TFrmCompanySearch) then

should be
if (aChild is TFrmCompanySearch) then
   
;-)
   
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7038737
listening
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7038748
nick, the listener ? :-)
0
 
LVL 2

Expert Comment

by:freshman3k
ID: 7040505
hello!

This should help you:

private
 { Private declarations }
 FClientInstance : TFarProc;
 FPrevClientProc : TFarProc;
 procedure ClientWndProc(var aMessage: TMessage);

implementation

procedure TfrmMForm.FormShow(Sender: TObject);
begin
FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
FClientInstance := MakeObjectInstance(ClientWndProc);
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FClientInstance));
end;

procedure TfrmMForm.FormClose(Sender: TObject);
begin
SetWindowLong(ClientHandle, GWL_WNDPROC, LongInt(FPrevClientProc));
end;

procedure TfrmMForm.ClientWndProc(var aMessage: TMessage);

procedure DoDefault;
 begin
    with aMessage do
      Result := CallWindowProc(FPrevClientProc,ClientHandle, Msg, wParam,lParam);
 end;

begin
  if aMessage.Msg = WM_MDIDESTROY then begin
     
{aMessage.Child is handle of the Mdi Child being closed}

    if aMessage.Child = FrmCompanySearch.Handle then begin    
        ToolBar1.Buttons[0].Enabled := true;
        end;
   
    if aMessage.Child = OtherMdiChildForm.Handle then
begin  
        ToolBar1.Buttons[1].Enabled := true;          
        end;
   
    DoDefault; {do defualt processing}
   end;
  else
    DoDefault;  {do defualt processing}
  end;
end;


Good Luck! ;-)
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7041013
Don't have time to answer all the time . So I "mark" :P the question and return latter . If is necesary .

So ...

const
  WM_DelChild = WM_User + 300;

type
  TMainForm = class(TForm)
...................................
private
    procedure CreateChild(const Name: string);
    procedure OnDelChild(var msg: TMessage); message WM_DelChild;  
    procedure OnChildDestroy(Sender: TObject);
.................

procedure TMainForm.OnDelChild(var msg: TMessage);
begin
  ShowMessage(' Just destroy me :( ');
end;

procedure TMainForm.OnChildDestroy(Sender: TObject);
begin
  PostMessage(TForm(MainForm).handle, WM_DelChild, 0, Integer(PChar('ChildName')));
end;

procedure TMainForm.CreateChild(const Name: String);
var
  Child: TChildForm;
begin
  Child := TChildForm.Create(Application);
  Child.Caption := Name;
  Child.OnDestroy := OnChildDestroy;
end;

0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7041163
Sorry :

1. Child unit

const
  WM_CloseWin = WM_User + 300;

type
  TChildForm = class(TForm)
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  end;

var
  ChildForm: TChildForm;

implementation

{$R *.DFM}

procedure TChildForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
var Buffer: array [0..99] of Char;
    s:string;
begin
  GetWindowText(TForm(Sender).Handle,buffer,100);
  s:=Buffer;
  PostMessage(Application.MainForm.handle, WM_CloseWin, 0, Integer(PChar(s)));
  Action := caFree;
end;

end.

2. Main unit

const
  WM_CloseWin = WM_User + 300;

type
  TMain = class(TForm)
...............
  private
    procedure OnCloseChild(var msg: TMessage); message WM_CloseWin;
    procedure CreateChild(const Name: string);
...............


procedure TMain.OnCloseChild(var msg: TMessage);
begin
  ShowMessage(Strpas(Pointer(msg.lparam)));
end;


0
 

Author Comment

by:muldeyur
ID: 7041170
Wow folks,

I'am going to try this when i get home,
Thanks to all that give advice,
will give the points as soon as i tried it!!

Regards,

Yuri
0
 

Author Comment

by:muldeyur
ID: 7042492
Thanks to all for the advice, but Kretzschmar was the quickest and also exactly what i Needed !

Thanks a lot,

Yuri
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
QRReport  TQrmemo vertical stretching 1 57
Delphi Yen format 3 62
Wincontrol not (correctly) drawn 15 48
Firemonkey Tcameracomponent resultion 1 25
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

726 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