John Kouraklis 94 Posted July 23, 2019 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
f.m 8 Posted July 23, 2019 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
Dave Nottage 557 Posted July 23, 2019 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
John Kouraklis 94 Posted July 23, 2019 So, they can't be swapped designtime? I need to it in code? Share this post Link to post
Bill Meyer 337 Posted July 23, 2019 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
John Kouraklis 94 Posted July 24, 2019 @Bill Meyer Can't find any relevant properties. The FlowGrid should expose the Controls property but sadly it doesn't Share this post Link to post
Bill Meyer 337 Posted July 24, 2019 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. Share this post Link to post
f.m 8 Posted July 24, 2019 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
John Kouraklis 94 Posted July 25, 2019 Unbelievable...the bring to back works Thanks @f.m Share this post Link to post