Board index » delphi » How to access MDI-Form's properties from MDI-Child-Form

How to access MDI-Form's properties from MDI-Child-Form

Hi There,

how to manage the following:
In my MDI-Form I have placed a TPanel and I want this Panel to show the
mouse coordinates above a created MDI-Child, when the mouse cursor is moved in
this MDI-Child.

TIA
Piotr

 

Re:How to access MDI-Form's properties from MDI-Child-Form


Hi There,

how to manage the following:
In my MDI-Form I have placed a TPanel and I want this Panel to show the
mouse coordinates above a created MDI-Child, when the mouse cursor is
moved in
this MDI-Child.

TIA
Piotr

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

There are several ways to do this.

The quick and dirty way is to simply access the component on the
MDI-Form like this:

frmMDIParent.LabelX.Caption := IntToStr(X);
frmMDIParent.LabelY.Caption := IntToStr(Y);

Be sure to add the following to the implementation section of the
MDI-Child unit so that you have access to frmMDIParent:

uses
        Parent;         {Parent.pas is source file for frmMDIParent}

You can't put this in the unit's uses clause (the first one) of the
file as this creates a circular reference (assuming that Parent.pas
specifies Child.pas in its unit's uses clause).

This of course, ties the code to KNOWING the structure of the MDI-Form parent.

So, in the interest of GOOD programming practices, here is another
way - create a public function and call that:

unit Parent
:
type
  TfrmMDIParent = class ...
        :
        public
                procedure SetMousePos(const X, Y: Integer);
        :
        end;
:
implmentation
:
procedure TfrmMDIParent.SetMousePos(const X, Y: Integer);
begin
  LabelX.Caption := IntToStr(X);
  LabelY.Caption := IntToStr(Y);
end;

unit Child
:
type
  TfrmMDIParent = class ...
:
implementation
:
uses
  Parent        {access to frmMDIParent}
:
:
  frmMDIParent.SetMousePos(X, Y);

taa-daah!

MarkR.

Re:How to access MDI-Form's properties from MDI-Child-Form


In article <506l5p$...@brachio.zrz.TU-Berlin.DE>, marc0...@mailszrz.zrz.tu-berlin.de (Piotr Marczuk) wrote:

Quote
>Hi There,

>how to manage the following:
>In my MDI-Form I have placed a TPanel and I want this Panel to show the
>mouse coordinates above a created MDI-Child, when the mouse cursor is moved in
>this MDI-Child.

>TIA
>Piotr

In the Implementation section of you MDI-Child's file add the line,

USES MDI-From;

(or whatever the name of your main form's file.)

Then you can access the Panel from the MDI-Form object.
eg.
        MDI-Form.Panel.visible:=true;

have fun. 8-)
--
Robert Howard                                    "Something Presented Well
Programming Manager                               Is Received Well."
Tasmanian Geological Drafting Services Pty Ltd.
---

Re:How to access MDI-Form's properties from MDI-Child-Form


In article <50ictb$...@merlin.tassie.net.au>, TGDS.Rod...@tassie.net.au says...

Quote

>In article <506l5p$...@brachio.zrz.TU-Berlin.DE>, marc0...@mailszrz.zrz.tu-berlin.de (Piotr
Marczuk) wrote:
>>Hi There,

>>how to manage the following:
>>In my MDI-Form I have placed a TPanel and I want this Panel to show the
>>mouse coordinates above a created MDI-Child, when the mouse cursor is moved in
>>this MDI-Child.

>>TIA
>>Piotr

>In the Implementation section of you MDI-Child's file add the line,

>USES MDI-From;

>(or whatever the name of your main form's file.)

>Then you can access the Panel from the MDI-Form object.
>eg.
>        MDI-Form.Panel.visible:=true;

>have fun. 8-)
>--
>Robert Howard                                    "Something Presented Well
>Programming Manager                               Is Received Well."
>Tasmanian Geological Drafting Services Pty Ltd.
>---

Thank You for this answer, but
that doesn't work because I 'use' the MDIchild in my MDIframe.
So Your solution would cause a cross reference in my use-statements.

Bye
Piotr

Other Threads