Board index » delphi » MDI app with 2 types of child

MDI app with 2 types of child

I'm writing a MDI app with two different MDI child types.
I want to apply a particular operation to all windows of
one type but not of the other.  I tried this:

  if TypeOf(MDIChildren[I]) = TypeOf(TChild1) then...

but the compiler moaned.  Is there an easy way to achieve
the same effect? (At the moment I'm checking window captions,
but I want to a more reliable method!).

Thanks in advance.

---------------------------------------------------------------
 John English              | mailto:j...@brighton.ac.uk
 Senior Lecturer           | http://www.comp.it.bton.ac.uk/je
 Dept. of Computing        | fax: (+44) 1273 642405
 University of Brighton    |
---------------------------------------------------------------

 

Re:MDI app with 2 types of child


Try something like this

function TWavesApp.IsArrayWindow(TF:TForm) : boolean;
begin
  if TF is TArray_data_win then IsArrayWindow:=true
  else IsArrayWindow:=false;
end;

procedure TWavesApp.findwinwithid(var Msg:TMessage);
var lp1 : integer;
  procedure check_win(T:TForm); far;
  begin if IsArrayWindow(T) and (TArray_data_win(T).titlenum=Msg.wparam)
then
    Msg.Result:=longint(T);
  end;
begin
  for lp1:= MDIChildCount-1 downto 0 do check_win(MDIChildren[lp1]);
end;

This does a check for window type, and my (common) base class stores
some extra info too.

hope this helps

John B

Re:MDI app with 2 types of child


On 25 Sep 1996 09:38:17 GMT, j...@bton.ac.uk (John English) wrote:

~I'm writing a MDI app with two different MDI child types.
~I want to apply a particular operation to all windows of
~one type but not of the other.  I tried this:
~
~  if TypeOf(MDIChildren[I]) = TypeOf(TChild1) then...
~
~but the compiler moaned.  Is there an easy way to achieve
~the same effect? (At the moment I'm checking window captions,
~but I want to a more reliable method!).
~
~Thanks in advance.

This looks like something which I had done before.  In order to
access/applies certain operation on all the MDI child with the same
types, you can do the following:

   for I := 0 to MDIChildCount-1 do begin
      if ActiveMDIChild is TfrmChartChild then
         (ActiveMDIChild as TfrmChartChild).Execute;
      if ActiveMDIChild is TfrmBMPViewer then
         (ActiveMDIChild as TfrmBMPViewer).Execute;
   end;

The above sample code is based on the assumption that it has two
MDIChild namely frmChartChild and frmBMPViewer.

HTH

Finest Regards,
Sam

 _       __    _____    _____            
| |     / /   / ___/   / ___/ ____   ____   ____ _
| | /| / /    \__ \    \__ \ / __ \ / __ \ / __ `/
| |/ |/ /  _ ___/ / _ ___/ // /_/ // / / // /_/ /
|__/|__/  (_)____/ (_)____/ \____//_/ /_/ \__, /
                                         /____/
**************************************************
   From the desk of Song Weng Sam

   Email : son...@pacific.net.sg
   WWW   : http://home.pacific.net.sg/~songws/SAM
   Tel   : (65)-271-7075 (0ffice)
   Pager : 9-492-4014
**************************************************

Re:MDI app with 2 types of child


Quote
In article <52aui9$...@saturn.brighton.ac.uk>, j...@bton.ac.uk (John English) wrote:
>I'm writing a MDI app with two different MDI child types.
>I want to apply a particular operation to all windows of
>one type but not of the other.  I tried this:

>  if TypeOf(MDIChildren[I]) = TypeOf(TChild1) then...

>but the compiler moaned.  Is there an easy way to achieve
>the same effect? (At the moment I'm checking window captions,
>but I want to a more reliable method!).

if (MDIChildren[i] is TChild1) then
begin
  TChild1(MDIChildren[i]).callATChild1Method;
end

or

try
  with (MDIChildren[i] as TChild1) do
    callATChild1Method;
except
  on EInvalidCast do
    ShowMessage('It was not a TChild1!');
end;

Hope this helps...Jim.

_______________________________________________________________________
James A. O'Brien, Director of R&D
Performance Trading Technologies, Inc.      Ask about The Profile Analyzer (tm)
HQ:  1501 Third Avenue, 4th Floor, New York, NY 10028      +1 (212) 517-1662
R&D:  132 Cherry Hill Road, Orange CT 06477      +1 (203) 891-8333
Wiz...@PTTI.com      http://www.PTTI.com

Re:MDI app with 2 types of child


On 25 Sep 1996 09:38:17 GMT, j...@bton.ac.uk (John English) wrote:

Quote
>I'm writing a MDI app with two different MDI child types.
>I want to apply a particular operation to all windows of
>one type but not of the other.  I tried this:

>  if TypeOf(MDIChildren[I]) = TypeOf(TChild1) then...

>but the compiler moaned.  Is there an easy way to achieve
>the same effect? (At the moment I'm checking window captions,
>but I want to a more reliable method!).

if MDIChildren[i] is TChild1 then...
--
Stefan Hoffmeister                       Stefan.Hoffmeis...@Uni-Passau.de
University of Passau, Bavaria, Germany  

Re:MDI app with 2 types of child


son...@pacific.net.sg (Song Weng Sam) wrote:

Quote
>   for I := 0 to MDIChildCount-1 do begin
>      if ActiveMDIChild is TfrmChartChild then
>         (ActiveMDIChild as TfrmChartChild).Execute;
>      if ActiveMDIChild is TfrmBMPViewer then
>         (ActiveMDIChild as TfrmBMPViewer).Execute;
>   end;

Not to be too picky or anything, but the use of AS is redundant,
because you have already established what type the object is.  A type
cast would be more appropriate and more efficient:

   for I := 0 to MDIChildCount-1 do begin
      if ActiveMDIChild is TfrmChartChild then
        TfrmChartChild (ActiveMDIChild).Execute;
      if ActiveMDIChild is TfrmBMPViewer then
         TfrmBMPViewer(ActiveMDIChild).Execute;
   end;

Re:MDI app with 2 types of child


Quote
On Thu, 26 Sep 1996 21:28:36 GMT, na...@vivid.net wrote:

~>   for I := 0 to MDIChildCount-1 do begin
~>      if ActiveMDIChild is TfrmChartChild then
~>         (ActiveMDIChild as TfrmChartChild).Execute;
~>      if ActiveMDIChild is TfrmBMPViewer then
~>         (ActiveMDIChild as TfrmBMPViewer).Execute;
~>   end;
~
~Not to be too picky or anything, but the use of AS is redundant,
~because you have already established what type the object is.  A type
~cast would be more appropriate and more efficient:
~
~   for I := 0 to MDIChildCount-1 do begin
~      if ActiveMDIChild is TfrmChartChild then
~        TfrmChartChild (ActiveMDIChild).Execute;
~      if ActiveMDIChild is TfrmBMPViewer then
~         TfrmBMPViewer(ActiveMDIChild).Execute;
~   end;

Hi,

Thanks for the tips.  I will try it next time around.  

Finest Regards,
Sam

 _       __    _____    _____            
| |     / /   / ___/   / ___/ ____   ____   ____ _
| | /| / /    \__ \    \__ \ / __ \ / __ \ / __ `/
| |/ |/ /  _ ___/ / _ ___/ // /_/ // / / // /_/ /
|__/|__/  (_)____/ (_)____/ \____//_/ /_/ \__, /
                                         /____/
**************************************************
   From the desk of Song Weng Sam

   Email : son...@pacific.net.sg
   WWW   : http://home.pacific.net.sg/~songws/SAM
   Tel   : (65)-271-7075 (0ffice)
   Pager : 9-492-4014
**************************************************

Other Threads