Board index » delphi » Talking to MDI Children

Talking to MDI Children

I'm currently writing an MDI application and need to set up some kind of
communication between the toolbar and the currently active child window,
i.e. When the Print button is pressed, the click event needs to activate
the current window's Print method.

The problem is that all the child windows are different types, such as
TfrmClientBrowse, TfrmUserMaint, etc.  The obvious solution would be to
have a huge set of IF statements in the button click event:

   if ActiveMDIChild is TfrmClientBrowse then
      TfrmClientBrowse( ActiveMDIChild ).Print;

   if ActiveMDIChild is TfrmUserMaint then
      TfrmUserMaint( ActiveMDIChild ).Print;

I can't help thinking that there must be a better way.

Is it possible to do this via Messaging?  If so, does anyone have any
examples?

TIA and a happy new year,
Alan

 

Re:Talking to MDI Children


Quote
Alan Taylor wrote:

> I'm currently writing an MDI application and need to set up some kind of
> communication between the toolbar and the currently active child window,
> i.e. When the Print button is pressed, the click event needs to activate
> the current window's Print method.

> The problem is that all the child windows are different types, such as
> TfrmClientBrowse, TfrmUserMaint, etc.  The obvious solution would be to
> have a huge set of IF statements in the button click event:

>    if ActiveMDIChild is TfrmClientBrowse then
>       TfrmClientBrowse( ActiveMDIChild ).Print;

>    if ActiveMDIChild is TfrmUserMaint then
>       TfrmUserMaint( ActiveMDIChild ).Print;

> I can't help thinking that there must be a better way.

> Is it possible to do this via Messaging?  If so, does anyone have any
> examples?

> TIA and a happy new year,
> Alan

Sure.
Define a message constant like

const

  WM_PRINTTHESTUFF  = WM_USER + 1;

then use
  SendMessage(ActiveMDIChild.Handle, WM_PRINTTHESTUFF, 0, 0);

Good Luck
Peter

Re:Talking to MDI Children


a...@athena.demon.co.uk,Usenet disse :
<<Is it possible to do this via Messaging?>>
You can do that using messaging or polimorphism. Create a common
ancestor form for all childs, with purely virtual functions. In the
chids you override the original functions.

Walter

--
+----- Walter Itamar Mourao ---------------------------------
| WIM Informatica Ltda. - wal...@wim.com.br - www.wim.com.br
| MetaLink Ltda. - w...@metalink.com.br - www.metalink.com.br
+------------------------------------------------------------

Other Threads