Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
852 views
in Technique[技术] by (71.8m points)

delphi - How to avoid issues when embedding a TForm in another TForm?

I often embed a TForm descendant into another TForm descendant like this:

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

Usually this works just fine, but sometimes the controls in Form2 are not aligned properly. Is there a general workaround for this sort of problem?

Does anybody know what is causing this "misalignment"?

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

Edit: I have identified the component TcxListView as the culprit here, I have submitted a bug report to the component vendor (DevExpress):

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

Edit 2: The developers at DevExpress have analyzed the problem and said that it is actually a defect in the TGridPanel component by Embarcadero:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I do this as well and I use the following routine to make it happen:

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

I have no problems with this. The only difference that I could possibly imagine could be relevant is the assignment of BorderIcons, but I would doubt that causes a problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...