Board index » delphi » Forms within Forms and inheritance

Forms within Forms and inheritance

Im trying to do MDI type stuff without using MDI (because of various
problems with it).  But...

At design time I create two forms.  Form1 and Form2.  

At run time, I can create I can create a 'Form2' and make it appear in
the main 'Form1' as follows...

procedure TForm1.CreateChild;
begin
  with TForm2.Create (self) do
  begin
    Parent := self;
    Show
  end
end;

This all works fine.

Suppose I drop 2 buttons on form 2.  Make button1's click
handler look like this:

procedure TForm2.Button1Click(Sender: TObject);
 begin
  ActiveControl := Button2;
end;

It still all works fine.

HOWEVER,  I create a new form - Form3, and make it inherited from Form 2
using form inheritance, and I drop two more buttons on it - Button3 and
Button4.  I make button3's click handler look like this:

procedure TForm3.Button1Click(Sender: TObject);
 begin
  ActiveControl := Button4;
end;

When I run it and click button3, I get an exception at the
'ActiveControl := Button2' line.  Looking at the VCL source, It will
throw this exception if the ultimate parent of a control is not the
form it's on.  In this case the ultimate parent of the buttons is
Form2, whereas their owner is form3, so I get the exception.

*  This seems to be a bug in the VCL (maybe with GetParentForm)

PS.  The work-around is to say GetParentForm (Button3).ActiveControl :=
Button4;

Colin
e-mail :co...@wilsonc.demon.co.uk
web: http://www.wilsonc.demon.co.uk/delphi.htm

 

Re:Forms within Forms and inheritance


Hi Colin,

Is this D4 ? I've got a large project making heavy use of embedded forms
and form inheritance where many properties and events are set in code.
This is in D3 and works very well. I did read that D4 has problems with
form inheritance, including (possibly only) in D4.02. Have a look in
non-technical - I'm sure there are messages relating to this.

Cheers,
Carl

Quote
Colin Wilson wrote:

> Im trying to do MDI type stuff without using MDI (because of various
> problems with it).  But...

> At design time I create two forms.  Form1 and Form2.

---8<---

Re:Forms within Forms and inheritance


Colin,

do you get the exception if you replace the

  ActiveControl:= ButtonX;

with a simple

  ButtonX.Setfocus;

?

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Re:Forms within Forms and inheritance


No - that works fine....

Colin
e-mail :co...@wilsonc.demon.co.uk
web: http://www.wilsonc.demon.co.uk/delphi.htm

Re:Forms within Forms and inheritance


Colin,

    I know this is a different situation from what we're doing, however, I
think it might apply.  The following code is what we're using to do
"sub-forms":

procedure TChildForm.CreateParams(var Params : TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
    begin
      Style:=(Style OR WS_CHILD) AND (NOT WS_POPUP);
      WndParent:=HostPanel.Handle;
    end;
  Parent:=HostPanel;
  Align:=alClient;
end;

I don't know what your exact code looks like for creating the form on the
other form, however probably similar, but without the "AND (NOT WS_POPUP)"
in the style.  From what we've experienced, it seems like after the form
"wndparent" is assigned it acts more like a tcontrol then a tform.  I don't
have an exact answer to your problem except to treat the form as such.  Our
problems with this tcontrol type activity mainly came about when we wanted
to DLL out our sub-forms.  Which, if Peter is reading this, I wanted to
thank you for trying to assist.  I did overcome our difficulty with window
hooks, however it was a long and painful experience.  Best of luck, and I'd
love to hear how you overcome this.

Best wishes,

Michael P. Bobowski
Atled Engineering Group
Milwaukee, WI, USA
e-mail: mb...@execpc.com

p.s. - Thank you, Colin, for making those LanMan units available to everyone
out here.  And if I can be any assistance in your current efforts, just let
me know!

Other Threads