Recent

Author Topic: Order of Aligned controls - difference from 2.0.6 to 2.0.8 or FPC 3.0.4 problem  (Read 631 times)

Birger52

  • Sr. Member
  • ****
  • Posts: 270
I have a control derived from TPanel (container), holding a number of controls derived from TCustomControl (columns).
These column controls all have Align:=alLeft - except the last one (Fav) that has Align:=alClient.
Used to be, this was working just fine (lazarus 2.0.6 - don't remeber FPC version).
In Lazarus 2.0.8 FPC 3.0.4, the order is not the one designed -and it's not following z-order either.
According to documentation, the order of controls with the same alignment is determined by the set value of the Left property - and this is not what happens in 2.0.8 either.

So how does one change the order of controls with the same setting of Align?
(using Anchors would be an option, but Anchors are not available in TCustomControl)
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Blaazen

  • Hero Member
  • *****
  • Posts: 2912
  • POKE 54296,15
    • Eye-Candy Controls
Don't know about Align (I use it seldom) but I'm pretty sure that Anchors are available in TCustomControl (it is public property so you need to do it published in your derived control to make it available in OI).
Lazarus 2.1.0 r63881 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Birger52

  • Sr. Member
  • ****
  • Posts: 270
Yes - Anchors can be made available.
So I rebuild my components, and set it all up using Anchors - which in this case is making a simple thing unnecessarily complicated, but it does get the job done....

But it doesn't explain why Align no longer functions...


Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

wp

  • Hero Member
  • *****
  • Posts: 7529
When you add a left-aligned control to a parent the controls sets is Left property to 0. When you add a second left-align control there are two controls with Left=0. IIRC I think the first control is moved to the right to solve the conflict.

All you have to do to bring the controls back into the correct order (first control at left, 2nd control next to the right, etc) is: you only must set Left to some large value for all the related controls. This attempts to move the first control far beyond the right-most control, but because Align=alLeft the control is only moved to the right of the right-most control. Repeating this for all controls effectively reverses the order of the controls.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormActivate(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   for i:=0 to ControlCount-1 do
  6.     if (Controls[i] is TPanel) and (Controls[i].Align = alLeft)
  7.       then Controls[i].Left := Width;
  8. end;
  9.  
  10. procedure TForm1.FormCreate(Sender: TObject);
  11. begin
  12.   with TPanel.Create(self) do
  13.   begin
  14.     Parent := self;
  15.     Caption := '1';
  16.     Align := alLeft;
  17.   end;
  18.  
  19.   with TPanel.Create(self) do
  20.   begin
  21.     Parent := self;
  22.     Caption := '2';
  23.     Align := alLeft;
  24.   end;
  25.  
  26.   with TPanel.Create(self) do
  27.   begin
  28.     Parent := self;
  29.     Caption := '3';
  30.     Align := alLeft;
  31.   end;
  32. end;

Alternatively you can create the controls in reverse order.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Birger52

  • Sr. Member
  • ****
  • Posts: 270
I know how it used to function.
The left property value is actually set when there are more than one, according to the position in the container.
But it is only used at designtime - used to be, the left property determined the position also at runtime.
This is not so in Lazarus 2.0.8 - and there seem to be no logic to the order at runtime.

Your example functions at designtime - not at runtime.

What you're suggesting is I manually edit the .lfm file, to alter the order, to get controls shown in the order I want them?
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 3522
Maybe your Z order could be edited if you are doing this from the OI..

Right click the control and you should see the Z - order option...
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 7529
Your example functions at designtime - not at runtime.

What you're suggesting is I manually edit the .lfm file, to alter the order, to get controls shown in the order I want them?
I don't understand. My example is for runtime, so why do you say it is for designtime? And I also did not recommend to edit the lfm file because the run-time created control doe not exist in the lfm file.
« Last Edit: July 05, 2020, 03:51:35 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018