2

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 ?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Joc02
  • 345
  • 8
  • 18
  • Seems to work ok in XE5. Installing XE6 om my laptop, may take a while ... – LU RD Jul 11 '14 at 10:41
  • 2
    AutoSize -> Adjust form size automatically. alTop -> Adjust panel size automatically. No good using both, one of them should have precedence, which would purely depend on implementation detail. – Sertac Akyuz Jul 11 '14 at 10:58
  • @SertacAkyuz I'm not so sure – `alTop` does more than adjust size, it positions controls too. – David Heffernan Jul 11 '14 at 11:05
  • @David - What it does more does not change the fact that it is resized automatically to fit in its parent. – Sertac Akyuz Jul 11 '14 at 11:08
  • @SertacAkyuz It seems to me that `AutoSize` and `Align` are expected to work together. When you put aligned controls in an auto-sized container, the controls are no longer resized. The controls are positioned, and the container is resized to match the size of the controls. Not that I can find any documentation to that effect. – David Heffernan Jul 11 '14 at 11:14
  • @David - Incomplete documentation wouldn't surprise me. However it's not straightforward to implement.. Consider an alTop and an alBottom panel with different widths... The outcome would still depend on implementation detail. – Sertac Akyuz Jul 11 '14 at 12:21
  • @SertacAkyuz Yes it would. – David Heffernan Jul 11 '14 at 12:22

2 Answers2

3

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;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • `Panel.Parent := Self;` triggers `OnFormResize` event in XE5, but not in XE6. I'm puzzled why this change in behaviour was introduced. – LU RD Jul 11 '14 at 14:13
0

Not align, use anchors:

t.Anchors:=[TAnchorKind.akTop];

This is from my XE5 (have no XE6)

LHristov
  • 1,103
  • 7
  • 16