5

I have a panel inside another:

enter image description here

The inner panel is aligned alTop:

enter image description here

And the outer panel is set to AutoSize=true:

enter image description here

And everything sizes. If i changes the height of the inner panel at design time, the outer panel auto sizes to accommodate it:

enter image description here

And now runtime

Now i need to change the height of the inner panel at runtime:

procedure TForm2.Button1Click(Sender: TObject);
begin
    pnlInner.Height := pnlInner.Height + 50;
    lblPointer.Top := pnlOuter.Top + pnlInner.Height;
end;

Except when i change the height of the inner panel at runtime, the autosize panel does not autosize:

enter image description here

This of course worked in Delphi 5, 7, and probably XE2 - XE5.

What's the fix?

The workaround is, of course, to bypass Alignment/Autosize and do everything during various OnResize events. But that's distinctly not RAD. I'm sure it's a small bug in the VCL somewhere. And since we already have about two-dozen XE6 VCL bugs that we've patched, it would be better to fix it so nobody else has to think about it.

Bonus Chatter

I love the line:

and, could you please attach sample project?

It's almost as if nobody bothered to even try to reproduce it.

Community
  • 1
  • 1
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • 1
    A quick fix is to upgrade to XE7 :-). Cannot replicate the issue in XE7 Upd 1. – LU RD Apr 01 '15 at 16:13
  • 1
    Not sure why somebody decided to downvote this. – Jerry Dodge Apr 01 '15 at 16:31
  • 1
    @LURD We already forked over a few thousand dollars for XE6, and we've still not managed to ship anything yet because of the bugs. Imagine if Ian now goes back and says we have to fork over a few thousand more for XE7; [which still hasn't fixed the bugs from 2005!](http://stackoverflow.com/questions/25449362/xe6-tlistview-column-widths-become-zero-if-you-read-column-width) I really with Embarcadero would release fixes for existing products. – Ian Boyd Apr 01 '15 at 16:54
  • So do all of us !!! At least there will be a change in the future, where a version will be maintained and updated for a longer period. (If you have a subscription !). – LU RD Apr 01 '15 at 17:06
  • @LURD Can you diff Controls.pas so i can find the bugfix? – Ian Boyd Apr 01 '15 at 18:09
  • @LURD [Vcl.Controls.pas](https://filetea.me/t1sW2IANxW6SzSt6vccxG5Rzw) for XE6 Update 1 – Ian Boyd Apr 01 '15 at 18:28
  • @LURD I think when i navigated away it deleted it. I tried pastebin, i tried mega, i tried others. I give up. – Ian Boyd Apr 01 '15 at 18:31
  • @LURD Unlisted [PasteBin](http://pastebin.com/) works great. I would have put `Vcl.Control.pas` up there already; but they have a 512kB limit. – Ian Boyd Apr 01 '15 at 21:05
  • @LU RD - where did you get this idea ? Once a new version is released they don't fix bugs in older versions, subscription or not. Never have. Never will. It just means that you have to hope that the 6 monthly release cycle won't routinely break any dependencies on 3rd parties who are slow in updating components for any breaking changes. You have to keep up-to-date otherwise why pay for a sub ? The drive to compel people to take out subs has been justified by claims that it would improve quality by securing the revenue to fix bugs etc but the reality flies in the face of that expectation. – Deltics Apr 02 '15 at 02:17
  • Upgrade IDE is kinda of sales recommendation, which costs you a lot of money to cover their ass. Have you set `anchor` for that. – stanleyxu2005 Apr 02 '15 at 05:23
  • @Deltics, see [RAD Studio Update Subscription](http://blog.marcocantu.com/blog/2015-january-radstudio-update-subscription.html). – LU RD Apr 02 '15 at 05:37
  • 1
    @Deltics I certainly would prefer that Embarcadero supported their products. Microsoft supports Visual Studio for 5 years. Embarcadero abandons their product 3 months after we gave them $3,000. In any other business you'd call the credit card company to get a chargeback. – Ian Boyd Apr 02 '15 at 13:51
  • @LURD It didn't work. And the Delphi 7 XE trial doesn't have VCL source. And XE7 is not yet up on TPB. It does work; there are two `if Showing then DoAdjustSize` blocks. i picked the wrong one. – Ian Boyd Apr 02 '15 at 15:44

2 Answers2

6

The issue is a regression in TWinControl.AlignControls:

procedure TWinControl.AlignControls(AControl: TControl; var Rect: TRect);
begin
   //...snip

   // Apply any constraints
   if Showing and ((sfWidth in FScalingFlags) or (sfHeight in FScalingFlags)) then
      DoAdjustSize;

   //...snip
end;

The bug here is that it will not call DoAdjustSize unless either sfWidth or sfHeight scaling flags are present.

The fix is to not try to outsmart yourself, and DoAdjustSize regardless:

procedure TWinControl.AlignControls(AControl: TControl; var Rect: TRect);
begin
   //...snip

   // Apply any constraints
   //QC125995: Don't look to scaling flags to decide if we should adjust size
   if Showing {and ((sfWidth in FScalingFlags) or (sfHeight in FScalingFlags))} then
      DoAdjustSize;

   //...snip
end;

With this fix found, we're halfway to solving the similar issue except with a TOleControl (e.g. TWebBrowser) rather than a TPanel.

Note: Any code released into public domain. No attribution required.

Community
  • 1
  • 1
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
5

This is reported in Embarcaderos Quality Central:

  • QC125995: [Regression in XE6 Update1] TPanel.AutoSize is not working
  • QC129330: AutoSize property is not always applied

I can reproduce this with XE6, but not with XE7.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54