Refering to controls in MDI forms.

I'm making  a simple text editor and want to add MDI support. But a problem has aroused, I want to load a text file to the RichText from the current window. How do I do that? I mean, reference a control located in the Active MDIChild form.
pablocastaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
hi pablocasta

so can it be done
(the unit of the main-form)

unit mdi_ed_main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus;

type
  TMain = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    New1: TMenuItem;
    Load1: TMenuItem;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Save1: TMenuItem;
    procedure New1Click(Sender: TObject);
    procedure Load1Click(Sender: TObject);
    procedure Save1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Main: TMain;

implementation
uses mdi_ed_child;  //holds the mdiChildForm-Object TChild

{$R *.DFM}

procedure TMain.New1Click(Sender: TObject);
begin
  TChild.Create(self);  //Create Empty Child
end;

procedure TMain.Load1Click(Sender: TObject);
begin
  If Opendialog1.Execute then
  begin
    if Not(self.ActiveMDIChild is TChild) then
      TChild.Create(Self);  //if there no child, then create one
    TChild(self.ActiveMDIChild).Richedit1.Lines.LoadfromFile(Opendialog1.FileName);
  end;
end;

procedure TMain.Save1Click(Sender: TObject);
begin
  if (self.ActiveMDIChild is TChild) then
    If Savedialog1.Execute then  //save current child-text
      TChild(self.ActiveMDIChild).Richedit1.Lines.SaveToFile(Savedialog1.FileName);
end;

end.

meikl ;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AttarSoftwareCommented:
Can I recommend that you don't use MDI?  Even Microsoft don't use it for MS Word...

Basically, it all works fine, up until the point you want to start doing anything interesting, and then it stops working...

Just my experience after a 2 month old project had to be rewritten here, as MDI is so bad....

Good luck...

Tim.
0
pablocastaAuthor Commented:
fine code.

and, i would LOVE no to use MDI, but must!
sorry
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.