TPanel does not AutoSize when containing a TPanel
Asked Answered
S

2

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.

Stealing answered 1/4, 2015 at 15:33 Comment(13)
A quick fix is to upgrade to XE7 :-). Cannot replicate the issue in XE7 Upd 1.Maccarone
Not sure why somebody decided to downvote this.Megaspore
@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! I really with Embarcadero would release fixes for existing products.Stealing
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 !).Maccarone
@LURD Can you diff Controls.pas so i can find the bugfix?Stealing
@LURD Vcl.Controls.pas for XE6 Update 1Stealing
@LURD I think when i navigated away it deleted it. I tried pastebin, i tried mega, i tried others. I give up.Stealing
@LURD Unlisted PasteBin works great. I would have put Vcl.Control.pas up there already; but they have a 512kB limit.Stealing
@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.Isochronous
Upgrade IDE is kinda of sales recommendation, which costs you a lot of money to cover their ass. Have you set anchor for that.Jonellejones
@Deltics, see RAD Studio Update Subscription.Maccarone
@Isochronous 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.Stealing
@LURD <strike>It didn't work. And the Delphi 7 XE trial doesn't have VCL source. And XE7 is not yet up on TPB.</strike> It does work; there are two if Showing then DoAdjustSize blocks. i picked the wrong one.Stealing
S
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.

Stealing answered 2/4, 2015 at 19:51 Comment(0)
F
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.

Feeney answered 1/4, 2015 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.