Quantcast
Channel: Delphi – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 1445

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

$
0
0

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:

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

–jeroen


Viewing all articles
Browse latest Browse all 1445

Trending Articles