Board index » delphi » Accessing components in MDI child-windows

Accessing components in MDI child-windows

How can I access components in MDI child windows - for example an edit
component? I know that I can retrieve the active child window by using
MainForm.ActiveMDIChild - but using textstring :=
MainForm.ActiveMDIChild.Edit1.Text won't work, nor does textstring :=
ChildForm.Edit1.Text.
 

Re:Accessing components in MDI child-windows


Quote
In article <3938c694@dnews>, Wolfgang Siebenbrger wrote:
> How can I access components in MDI child windows - for example an edit
> component? I know that I can retrieve the active child window by using
> MainForm.ActiveMDIChild - but using textstring :=
> MainForm.ActiveMDIChild.Edit1.Text won't work, nor does textstring :=
> ChildForm.Edit1.Text.

You have to typecast the ActiveMDIChild by doing

 TMyChildForm(MainForm.ActiveMDIChild).Edit1.Text

where TMyChildForm is the name you have given to your MDI child form
with a T in front.

Tony Bryer  SDA UK

Re:Accessing components in MDI child-windows


Quote
In article <3938c694@dnews>, Wolfgang Siebenbrger wrote:
> How can I access components in MDI child windows - for example an edit
> component? I know that I can retrieve the active child window by using
> MainForm.ActiveMDIChild - but using textstring :=
> MainForm.ActiveMDIChild.Edit1.Text won't work, nor does textstring :=
> ChildForm.Edit1.Text.

It fails because ActiveMDIChild returns a reference of type TForm. TForm
has no controls on it. You can get around this by typecasting to your
childform class, e.g.

  (Mainform.ActiveMDIChild As TMDIChild).edit1.text := ...;

but i consider such things to be very bad programing style. It completely
violates encapsulation and creates strong dependencies between the child
form and code outside it. A childform should be as self-contained as
possible (in fact any class should be this way) and if you have to
manipulate it from outside for some reason ask the childform to do it (by
sending it a message or calling a method in it) instead of directly digging
around in the childforms innards from outside.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads