Delphi XE6 TForm.AutoSize

2019-07-17 04:48发布

问题:

I've code in Delphi XE2 who work perfectly. But in Delphi XE6 it doesn't work. I create a Tform with the property AutoSize to true. I use a TPanel align alTop with a button for create some another panels.

procedure TForm2.Button1Click(Sender: TObject);
var
   t :TPanel;
begin
   t := TPanel.Create(self);
   t.Parent := self;
   t.Align := alTop;
end;

The form doesn't auto size. If I want to see all my panels I have to move the form (or try to resize, ....).

Have you any idea's ?

回答1:

This is indeed a change in behaviour. I can reproduce what you report. Namely that your code results in the form size changing in XE2, but not in XE6.

To work around this you can manually call AdjustSize:

procedure TForm1.Button1Click(Sender: TObject);
var
  Panel: TPanel;
begin
  Panel := TPanel.Create(self);
  Panel.Parent := Self;
  Panel.Top := ClientHeight;
  Panel.Align := alTop;
  AdjustSize;
end;


回答2:

Not align, use anchors:

t.Anchors:=[TAnchorKind.akTop];

This is from my XE5 (have no XE6)