Board index » delphi » Referencing MDI form controls from diff form ?

Referencing MDI form controls from diff form ?

I have a MDI application with named Mainform and Subform. Both forms
reference each other in their respective Implementation/Uses section.
I can access controls on the subfrom from within the mainform by using
Tsubform(activeMDIchild).whatever, but can't access controls on the
mainform from within the subform by mainform.whatever.

This works:
  procedure TmainForm.User3Click(Sender: TObject);
  begin
    tsubform(activeMDIchild).memo1.seltext := 'hello';
  end;

while this GPFs:
  procedure TSubForm.User3Click(Sender: TObject);
  begin
    mainform.memo1.seltext := 'hello';
  end;

There is no way I can get around having to access controls on the
Mainform from the subform, so I'd really appreciate any ideas.

Ashley

 

Re:Referencing MDI form controls from diff form ?


To access the main form from the MDi form use the following :

   procedure TSubForm.User3Click(Sender: TObject);
   begin
     Tmainform(Owner).memo1.seltext := 'hello';
   end;

Ashley Bass <ab...@fyi.net> wrote in article
<32a3d24d.5721...@news.alt.net>...

Quote
> I have a MDI application with named Mainform and Subform. Both forms
> reference each other in their respective Implementation/Uses section.
> I can access controls on the subfrom from within the mainform by using
> Tsubform(activeMDIchild).whatever, but can't access controls on the
> mainform from within the subform by mainform.whatever.

<<< SNIP >>>
Quote
> while this GPFs:
>   procedure TSubForm.User3Click(Sender: TObject);
>   begin
>     mainform.memo1.seltext := 'hello';
>   end;

> There is no way I can get around having to access controls on the
> Mainform from the subform, so I'd really appreciate any ideas.

> Ashley

Other Threads