Solved

Silly question...

Posted on 2003-11-17
14
285 Views
Last Modified: 2010-04-05
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!!!
0
Comment
Question by:Prototype_T-104
  • 4
  • 3
  • 3
  • +2
14 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9764817
Say your MDIChild is named Child2...

  Child2.RichEdit1

should do it...

0
 
LVL 2

Expert Comment

by:sgc_romania
ID: 9764818
MainForm.ActiveMDIChild.richedit1
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9764854
Suppose it is NOT the Active child???
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9764897
TFormClassWithRichedit(ActiveMDIChild).richedit1

or

TFormClassWithRichedit(MDIChildren[index]).richedit1

whereas
TFormClassWithRichedit is the Class declaration od your MDIChild

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9764905
typo
od -> of
0
 

Author Comment

by:Prototype_T-104
ID: 9766693
hmmm i am still getting error: "Undeclared identifier : RichEdit1".
I don't get it...
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9766910
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.
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9770341
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.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9770403
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]).RichEdit1.Lines.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 ;-)
0
 

Author Comment

by:Prototype_T-104
ID: 9770678
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.Add('sdkfsdh')- 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.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 9770709
...
begin
  //just use the conversion (TForm2 is the childformClass here)
  if (ActiveMDIChild is TForm2) then
    TForm2(ActiveMDIChild).RichEdit1.Add('sdkfsdh');
end;

meikl ;-)
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9770723
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('asldkajslkd');

or, check to see which class the Active chlid is..

if ActiveMDIChild is TFirstChlidForm then
  TFirstChildForm(ActiveMDIChild).RicheEdit1.Add('asdasd');
else if ActiveMDIChlid is TSecondChildForm then
  TSecondChlidForm(...)...
else ...

etc.

depending on how many chlid form class types you've got.

0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9770736
NB "You can't do it directly that way" applies to T-104's last comment, not meikl's !

0
 

Author Comment

by:Prototype_T-104
ID: 9770833
Thanks alot guys you helped me alot!! it works now!!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question