[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • Last Modified:

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.
0
pablocasta
Asked:
pablocasta
1 Solution
 
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
 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now