Board index » delphi » MDIChild event triggering

MDIChild event triggering

Hi gurus,

I have an MDI application.

I have a toolbar on the main form and I want some of the buttons to
trigger events inside the Child window the same way the Merged menus
do. How do I go about this?

I can't seem to link a button-click in the MainForm to an action in
the current active child.

Let's say I wanted to use the find dialog in the child. I can use the
merged menu to do it but I want to be able to click the button on the
MainFrom to do it. Currently each child has it's own toolbar but this
seems wasteful. Is there some way I can have just the one toolbar on
the MainForm and have it perform in the child?

I am trying to emulate the merging of the menus, I guess, but with the
toolbar instead.

Any help here would be appreciated as this is my first foray into MDI.

Regards

Peter Nolan
CEO - Nolan Innovation Inc.
*******************************
http://aluminator.tierranet.com
Ph 520-772-9730
Cellular 520-713-7016
Fax 520-772-9839
***********************************

 

Re:MDIChild event triggering


In article <35e1fb1e.6393...@news1.ibm.net>, Peter Nolan <nolaninc@alumi
nator.tierranet.com> writes

Quote
>I have a toolbar on the main form and I want some of the buttons to
>trigger events inside the Child window the same way the Merged menus
>do. How do I go about this?

>I can't seem to link a button-click in the MainForm to an action in
>the current active child.

>Let's say I wanted to use the find dialog in the child. I can use the
>merged menu to do it but I want to be able to click the button on the
>MainFrom to do it. Currently each child has it's own toolbar but this
>seems wasteful. Is there some way I can have just the one toolbar on
>the MainForm and have it perform in the child?

>I am trying to emulate the merging of the menus, I guess, but with the
>toolbar instead.

>Any help here would be appreciated as this is my first foray into MDI.

There are several ways to achieve this - here are a couple of ideas.

Let's say your MDIChild has a menu, with a menu item called
"FindMenuItem". This menu gets merged with the main form's menu
and everything works fine.

Your main decision is whether to write the code for the button in
the main form or the child form. If you write it in the main form
(say the button is called "FindButton", and the MDI child form is called
"ChildForm"), then it would be something like this:

procedure TMainForm.FindButtonClick(Sender : TObject);
begin
  if ActiveMDIChild <> nil then
    TChildForm(ActiveMDIChild).FindMenuItemClick(Sender);
end;

If you write code in the child form, it would go a bit like this:

procedure TChildForm.FormActivate(Sender: TObject);
begin
  MainForm.FindButton.OnClick := FindMenuItemClick;
end;

procedure TChildForm.FormDeactivate(Sender: TObject);
begin
  MainForm.FindButton.OnClick := nil;
end;

The first method is better if all your MDI children are the same, the
second is probably better if you have several different child forms.

HTH
--
Jeremy Collins
Kansai Business Systems

Other Threads