Prototype_T-104
asked on
Silly question...
Hello,
I know i'm gonna get laughed at me... but can anyone tell me how to reference a RichEdit component from the main Form of an MDI App. where RichEdit is on the MDI Child form??? thanks alot!!!
I know i'm gonna get laughed at me... but can anyone tell me how to reference a RichEdit component from the main Form of an MDI App. where RichEdit is on the MDI Child form??? thanks alot!!!
MainForm.ActiveMDIChild.ri chedit1
Suppose it is NOT the Active child???
TFormClassWithRichedit(Act iveMDIChil d).richedi t1
or
TFormClassWithRichedit(MDI Children[i ndex]).ric hedit1
whereas
TFormClassWithRichedit is the Class declaration od your MDIChild
meikl ;-)
or
TFormClassWithRichedit(MDI
whereas
TFormClassWithRichedit is the Class declaration od your MDIChild
meikl ;-)
typo
od -> of
od -> of
ASKER
hmmm i am still getting error: "Undeclared identifier : RichEdit1".
I don't get it...
I don't get it...
You must include the unit that contains the MDIChild in your implementation uses clause.
From the Main Menu, select File->Use Unit and select the unit that contains the MDIChild
that contains the RichEdit.
From the Main Menu, select File->Use Unit and select the unit that contains the MDIChild
that contains the RichEdit.
Eddie's will work.
sgc_romana's wont.
kretzschmar's will, too, so long as you use the right class name(!)
Sounds like you're using Eddie's method.
sgc_romana's wont.
kretzschmar's will, too, so long as you use the right class name(!)
Sounds like you're using Eddie's method.
a sample
--- main-unit
unit mdi_re_main_u;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses mdi_re_child_u; //child-unit used
procedure TForm1.Button1Click(Sender : TObject);
begin
with TForm2.Create(self) do show;
end;
procedure TForm1.Button2Click(Sender : TObject);
var i, childs, lines : integer;
begin
childs := MDIChildCount;
lines := 0;
for i := 0 to MDIChildCount -1 do
if (MDIChildren[i] is TForm2) then
lines := lines + TForm2(MDIChildren[i]).Ric hEdit1.Lin es.Count;
Showmessage('There are '+inttostr(childs)+' Childs'+#10+
'Which are Containing in Sum '+inttostr(lines)+' Lines Text');
end;
end.
---- Child-Unit
unit mdi_re_child_u;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm2 = class(TForm)
RichEdit1: TRichEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action := caFree;
end;
end.
---------
meikl ;-)
--- main-unit
unit mdi_re_main_u;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses mdi_re_child_u; //child-unit used
procedure TForm1.Button1Click(Sender
begin
with TForm2.Create(self) do show;
end;
procedure TForm1.Button2Click(Sender
var i, childs, lines : integer;
begin
childs := MDIChildCount;
lines := 0;
for i := 0 to MDIChildCount -1 do
if (MDIChildren[i] is TForm2) then
lines := lines + TForm2(MDIChildren[i]).Ric
Showmessage('There are '+inttostr(childs)+' Childs'+#10+
'Which are Containing in Sum '+inttostr(lines)+' Lines Text');
end;
end.
---- Child-Unit
unit mdi_re_child_u;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm2 = class(TForm)
RichEdit1: TRichEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action := caFree;
end;
end.
---------
meikl ;-)
ASKER
Thanks but here is what i need. When i press a button on the toolbar, i want "You pressed button1..." or any other text to be displayed in the RichEdit1 of the Active MDIChild (something like ActiveMDIChild.RichEdit1.A dd('sdkfsd h')- only it doesn't work). Thanks very much for even reading up to here and i know i am very boring but i can't get this to work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can't do it directly that way. 'ActuveMDIChid' is a TForm. A TForm doesn't have a RichEdit1 component. So you can't do it generically.
Either:
Derive all your MDI child forms from some base class which _does_ have a RichEdit1 component.
Then you could do
TBaseMDIForm( ActiveMDIChlid ).RichEdit1.Add('asldkajsl kd');
or, check to see which class the Active chlid is..
if ActiveMDIChild is TFirstChlidForm then
TFirstChildForm(ActiveMDIC hild).Rich eEdit1.Add ('asdasd') ;
else if ActiveMDIChlid is TSecondChildForm then
TSecondChlidForm(...)...
else ...
etc.
depending on how many chlid form class types you've got.
Either:
Derive all your MDI child forms from some base class which _does_ have a RichEdit1 component.
Then you could do
TBaseMDIForm( ActiveMDIChlid ).RichEdit1.Add('asldkajsl
or, check to see which class the Active chlid is..
if ActiveMDIChild is TFirstChlidForm then
TFirstChildForm(ActiveMDIC
else if ActiveMDIChlid is TSecondChildForm then
TSecondChlidForm(...)...
else ...
etc.
depending on how many chlid form class types you've got.
NB "You can't do it directly that way" applies to T-104's last comment, not meikl's !
ASKER
Thanks alot guys you helped me alot!! it works now!!!
Child2.RichEdit1
should do it...