Jump to content
Sign in to follow this  
John Kouraklis

TFlowLayout

Recommended Posts

Hi,

does anyone know how to change the order of components in a TFlowLayout?

Trying to drag/drop them or change the position but no luck

Share this post


Link to post

Hi,

Try this:

 

procedure TForm1.FormCreate(Sender: TObject);
var
  LIndex: Integer;
  LRect : TRectangle;
  LText : TText;
begin
  for LIndex := 0 to 10-1 do
  begin
    LRect := TRectangle.Create( FlowLayout1 );
    LRect.Parent := FlowLayout1;
    LRect.Fill.Color := TAlphaColor($FF000000 or Random($00FFFFFF));

    LText := TText.Create( LRect );
    LText.Parent := LRect;
    LText.Align := TAlignLayout.Contents;
    LText.Text := IntToStr( LIndex );
    LText.TextSettings.FontColor := TAlphaColors.White;
    LText.HitTest := False;
  end;
end;


procedure TForm1.ButtonSwap5_6Click(Sender: TObject);
var
  LRect : TRectangle;
begin
  FlowLayout1.BeginUpdate();
  LRect := FlowLayout1.Controls[6] as TRectangle;
  FlowLayout1.Controls.Remove( LRect );
  FlowLayout1.Controls.Insert( 5, LRect );
  FlowLayout1.EndUpdate();
end;

 

Share this post


Link to post
32 minutes ago, f.m said:

Try this:

That's pretty much what I've needed to do, i.e. remove all that are not in the correct order, then insert in the correct order

Share this post


Link to post
5 minutes ago, John Kouraklis said:

So, they can't be swapped designtime? I need to it in code?

Don't they have a ControlIndex property added at the bottom of the Object Inspector? If they do, that's the way to control the ordering.

Share this post


Link to post

In 10.3, I just created a new app, placed a TFlowPanel on the form, then dropped in a few buttons. I selected a button, and in the ObjectInspector, I find ControlIndex. On Button1, it is zero. I change it to 1, and Button1 now moves to the right of Button2.

image.png.270fa6df4597def9c30e8e404b1adf09.png

Share this post


Link to post

 TFlowLayout is for FMX, while TFlowPanel is for VCL.


At design time, it is possible to change (quite) the position using menu item Control|Bring to front/Send to back. 

 

Or, expose the control's index property:

 

uses
  System.Classes, FMX.StdCtrls;


type
  TButtonIndex = class (TButton)
  published
    property Index;
  end;

procedure Register;

implementation


procedure Register;
begin
  {System.Classes}RegisterComponents('With index', [TButtonIndex]);
end;

 

Or, use LiveBinding to bind the control's index property. I've never used LiveBinding and can't show an example. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×