Delphi Ensuring Left/alLeft or Top/alTop controls are positioned in the right order…

  

The post [WayBack] Why is my buttons not created in logical order? If I run this, my buttons area created ACB rather than ABC as I expected… – Johan Swart – Google+ reminded me the trouble of Delphi VCL and FMX have with alignment.
Basically you have to position your control away from your intended alignment position in order for it to work. So this fails:

procedure TForm1.FormCreate(Sender: TObject);
var
myToolBar: TToolBar;
myCornerButton: TCornerButton;
i: Integer;
begin
myToolBar := TToolbar.Create(Self);
myToolBar.Parent := Self;

for i := 0 to 2 do
begin
myCornerButton := TCornerButton.Create(tbarGrid);
myCornerButton.Parent := myToolBar;
myCornerButton.Align := TAlignLayout.Left;
myCornerButton.Text := Chr(65 + I);
end;
end;

Basically you have to set myCornerButton.Left to 1 before setting the Align property.
Similar for the Top property and TAlignLayout.Top value.
The same holds for VCL Align values alLeft with setting the Left property and alTop with setting the Top property before setting Align.
See these for the actual properties and types:

FMX:

FMX.Types.TAlignLayout
FMX.Controls.TControl.Align
FMX.Controls.TControl.Left
FMX.Controls.TControl.Top

VCL:

Vcl.Controls.TAlign
Vcl.Controls.TControl.Align
Vcl.Controls.TControl.Left
Vcl.Controls.TControl.Top

See also this question: [WayBack] Delphi: How to programmatically adjust visual ordering of components with align = alTop
–jeroen

Comments are closed.