How to avoid problems when embedding TForm in another TForm?

I often embed a TForm descendant into another TForm descendant as follows:

 var Form1: TForm1; Form2: TForm2; begin Form2.Parent := Form1; Form2.BorderStyle := bsNone; Form2.Align := alClient; Form2.Show; end; 

This usually works fine, but sometimes the controls in Form2 do not align properly. Is there a general way to solve this problem?

Does anyone know what causes this "misalignment"?

I know that I could use TFrame for this kind of work, but I have a lot of library code that I would have to rewrite, and I see no reason why the TForm in TForm should not work?

Edit: I identified the TcxListView component as the culprit here, I sent an error report to the component provider (DevExpress):

http://www.devexpress.com/issue=B194161

Edit 2: DevExpress developers analyzed the problem and said that it was actually a defect in the Embarcadero TGridPanel component:

http://qc.embarcadero.com/wc/qcmain.aspx?d=90324

+6
layout delphi vcl delphi-2007 tframe
source share
2 answers

I do this as well, and I use the following procedure to make this happen:

 procedure TMyForm.PlaceInsideContainer(Container: TWinControl); begin Parent := Container; Align := alClient; BorderIcons := []; BorderStyle := bsNone; ParentBackground := True; Show; end; 

I have no problem with this. The only difference I could imagine might be appropriate is the purpose of BorderIcons, but I would doubt that this is causing the problem.

+7
source share

I read a similar question (you will need to use it), and the answer from TeamB should not have done this, because the behavior was unpredictable, and you should use TFrame instead (this is what I always did).

+1
source share

All Articles