Lazarus

Free Pascal => Beginners => Topic started by: Birger52 on July 03, 2020, 01:09:27 pm

Title: Order of Aligned controls - difference from 2.0.6 to 2.0.8 or FPC 3.0.4 problem
Post by: Birger52 on July 03, 2020, 01:09:27 pm
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)
Title: Re: Order of Aligned controls - difference from 2.0.6 to 2.0.8 or FPC 3.0.4 problem
Post by: Blaazen on July 03, 2020, 03:07:48 pm
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).
Title: Re: Order of Aligned controls - difference from 2.0.6 to 2.0.8 or FPC 3.0.4 problem
Post by: Birger52 on July 03, 2020, 06:17:31 pm
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...


Title: Re: Order of Aligned controls - difference from 2.0.6 to 2.0.8 or FPC 3.0.4 problem
Post by: wp on July 03, 2020, 08:13:50 pm
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.
Title: Re: Order of Aligned controls - difference from 2.0.6 to 2.0.8 or FPC 3.0.4 problem
Post by: Birger52 on July 05, 2020, 01:22:44 am
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?
Title: Re: Order of Aligned controls - difference from 2.0.6 to 2.0.8 or FPC 3.0.4 problem
Post by: jamie on July 05, 2020, 02:19:49 pm
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...
Title: Re: Order of Aligned controls - difference from 2.0.6 to 2.0.8 or FPC 3.0.4 problem
Post by: wp on July 05, 2020, 03:45:41 pm
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.
TinyPortal © 2005-2018