On Thu, 4 May 2006 22:48:24 +0200
Borut Maricic <[EMAIL PROTECTED]> wrote:

> On 2006-05-04 at 18:30,
> Graeme Geldenhuys ([EMAIL PROTECTED]) wrote:
> 
> > You never showed the code for Panel1...?  How big is Panel1?
> > Also it isn't a good idea to declare f1, f2 and E as local variables
> > in FormCreate.  You will never be able to reference it again....
> 
> I just happened to browse this thread. With all due respect,
> what Todorov has made was - IMHO - an example that was
> recreating an issue. And the issue is still repeatable with
> no Panel1 and referring only to Form and using global
> component declarations, of course.
> 
> So, the original question is grounded and I will just
> restate it here:
> 
> The code sequence
> 
> f1 := TButton.Create(Form1);
> with f1 do begin
>  Parent := Form1; Align := alRight; Caption := '1';  end;
> 
> f2 := TButton.Create(Form1);
> with f2 do begin
>  Parent := Form1; Align := alRight; Caption := '2'; end;
> 
> positions buttons on the form like this
>             1 2
> while one would expect
>             2 1
> 
> The original Todorov's question was: Bug or a feature?

Short answer: Bug. Fixed.

Long answer:
The Align property is difficult. It is powerful, because you can 'align'
multiple controls, that don't need to know each other. But this is also a
drawback because it uses old positions, old order and current change to
recalculate the new layout. 
In the above example, the two buttons have no bounds, so they are positioned
at the default position (0,0,75,25).
When the f1.Align is set to alRight the VCL (Delphi) immediately repositions
all controls.
So, f1 is put rightmost (e.g. 235,0).
When the f2.Align is set to alRight the VCL compares the current potsitions
and since f2 (0,0) is left of f1 (235,0) it puts f2 left of f1. The result
is a lot of overhead and putting f1 right of f2.
The LCL has a lot more autosizing properties and must handle different
widgetsets. This would create even more overhead. That's why the LCL
disables autosizing when calling FormCreate. That means the code in the
FormCreate is not immediately executed. The LCL waits till the form layout
interdependencies are completely defined and then it calculates the layout.
That's why the LCL has f1 and f2, both at 0,0 and it has to decide, which
one to put rightmost. It used the Delphi heuristic (Controls.pas
InsertBefore). And this function decided to put f2 rightmost.
I don't know why Delhpi defined it that way. But obviously it does not work
intuitivly symmetric to alLeft. Maybe it was hardly used, as the VCL prefers
overhead for deterministic results, and this was treated as a minor bug.

I changed the lower/equal to lower for alRign and alBottom, so it is now
symmetric to alLeft, alTop.


Mattias

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to