TCoolBarBands (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

To run this example, add the example code to a new project. The example code dynamically creates a TCoolBar and three TCoolBand objects populated with a windowed control in each TCoolBand.

Code

procedure AddBand(CoolBar: TCoolBar; Const ControlClasses: array of TControlClass);
var
  CurrentControl: TControl;
  I: Integer;
begin
  for I := 0 to High(ControlClasses) do
    begin
      CurrentControl := ControlClasses[i].Create(CoolBar);
      if (CurrentControl is TWinControl) then
      begin
        { Placing the control onto the CoolBar causes the TCoolBar object to create a TCoolBand and place the control within the band. }
        CurrentControl.Parent := Coolbar;
        { Get the reference of the last TCoolBand created and assign text. }
        with CoolBar.Bands do
          Items[count - 1].Text := CurrentControl.ClassName;
      end;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  CoolBar: TCoolBar;
begin
  CoolBar := TCoolBar.Create(Self);
  CoolBar.Parent := Self;
  CoolBar.Align := alClient;
  AddBand(CoolBar, [TCheckBox, TEdit, TButton]);
end;

Uses