[Lazarus] New autosize sucks

Mattias Gaertner nc-gaertnma at netcologne.de
Fri Apr 23 10:17:03 CEST 2010


On Fri, 23 Apr 2010 08:14:37 +0200
zeljko <zeljko at holobit.net> wrote:

> On Thursday 22 April 2010 23:36, Mattias Gaertner wrote:
> > On Thu, 22 Apr 2010 17:36:36 +0200
> >
> > Hans-Peter Diettrich <DrDiettrich1 at aol.com> wrote:
> > > Is it only me, or have more users noticed the many changes, required to
> > > make existing code work without -dOldAutoSize?
> >
> > AFAIK you and me are the only one working on docking.
> >
> > > I understand that it may take some more time to finish the autosize
> > > redesign, so let me report some observations:
> >
> > According to the bug tracker there is only one issue left and no
> > developer can reproduce it:
> > http://bugs.freepascal.org/view.php?id=16184
> 
> I'm still using -dOldAutoSize for my projects since newAutoSize isn't 
> compatibile with K3/D7 way of resizing.
> eg. I'm resizing stringgrid columns in form OnResize event.

I added a FAQ:
http://wiki.lazarus.freepascal.org/Autosize_/_Layout#Resizing_stringgrid_columns_in_form.27s_OnResize_event_does_not_work

 
> With such example (new autosize) , maximize form -> nothing happens with grid,
> now restore form size, columns are resized but grid thinks that form is 
> maximized.
> var 
>   i: integer;
>   j: integer;
> begin
>   i := MyGrid.Width;
>   for j := 0 to MyGrid.ColCount - 1 do
>     MyGrid.ColWidths[j] := i div 10;
> end;
> 
> 
> 1.It works correct with -dOldAutoSize

Only sometimes, not always, as explained in the FAQ.

> 2.It works correct with Delphi/Kylix

I doubt that it always works, unless OnResize fires too often, even if
the bounds have not changed.
See here
http://docwiki.embarcadero.com/VCL/en/Controls.TControl.OnResize

"Occurs immediately after the control is resized."


> 3.It does not work correct with new autosize.

Formerly the OnResize was often triggered after the LCL did some
autosizing, so for simple form layouts the above worked sometimes. The
OnResize is now triggered earlier. I can change it to trigger the event
later, but as OnResize can trigger new autosizes, it can't be
guaranteed that it will be the final event.
The right solution is to use the TStringGrids OnResize.

I will change the event so that it works for some simple cases,
but I recommend that you fix your code.

 
> I have not enough time to investigate what's wrong but I know that my 
> tstringgrid columns aren't resized in form's OnResize event in case of new 
> autosize.Probably resize events are in opposite order so Form.OnResize is 
> triggered first but children are not resized yet. Yes, I know that you wrote 
> somewhere that we should use OnResize() for each control we want to track, 
> but what should I do now with my project which have > 400 forms, open each 
> form add OnResize to each control I need to resize ? 

I know what you mean.
But also think about the many new forms that are created and the many
users who wants a reliable and fast LCL. It can not be guaranteed that
form's OnResize comes after all the children are resized (unless it
triggers far too often and then we get bug reports). And the later
OnResize is triggered the more overhead it creates.


> Maybe I'm wrong (didn't look into), but seem that delphi/kylix triggers 
> form.OnResize when everything is resized inside form (children), or it 
> triggers twice : at form resize, and then after all children resized.

Don't forget that Delphi has a simple top down autosize algorithm. It
does not even support a theme independent groupbox with buttons. 


Mattias




More information about the Lazarus mailing list