Marco Cantù 1998, Mastering Delphi 4

Project: COMBOBAR.DPR


Project Structure


COMBOBAR.DPR

program Combobar;

uses
  Forms,
  ToolForm in 'ToolForm.pas' {ToolbarForm};

{$R *.RES}

begin
  Application.CreateForm(TToolbarForm, ToolbarForm);
  Application.Run;
end.

TOOLFORM.PAS

unit ToolForm;

interface

uses
  Windows, SysUtils, Classes, Graphics, Forms, Controls, Menus,
  Buttons, StdCtrls, Dialogs, ExtCtrls, Spin, ComCtrls, ActnList;

type
  TToolbarForm = class(TForm)
    Panel1: TPanel;
    SpeedButtonNote: TSpeedButton;
    SpeedButtonBold: TSpeedButton;
    SpeedButtonItalic: TSpeedButton;
    SpeedButtonUnderline: TSpeedButton;
    SpeedButtonLeft: TSpeedButton;
    SpeedButtonCenter: TSpeedButton;
    SpeedButtonRight: TSpeedButton;
    Label1: TLabel;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Exit1: TMenuItem;
    Toolbar1: TMenuItem;
    Visible1: TMenuItem;
    DisableSound1: TMenuItem;
    DisableStyles1: TMenuItem;
    Help1: TMenuItem;
    AboutToolbar1: TMenuItem;
    ComboBox1: TComboBox;
    PopupMenu1: TPopupMenu;
    Hide1: TMenuItem;
    N1: TMenuItem;
    DisableStyles2: TMenuItem;
    DisableSound2: TMenuItem;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    UpDown1: TUpDown;
    ActionList1: TActionList;
    actVisible: TAction;
    actDisableSounds: TAction;
    actDisableStyles: TAction;
    actExit: TAction;
    procedure SpeedButtonNoteClick(Sender: TObject);
    procedure SpeedButtonLeftClick(Sender: TObject);
    procedure SpeedButtonCenterClick(Sender: TObject);
    procedure SpeedButtonRightClick(Sender: TObject);
    procedure SpeedButtonBoldClick(Sender: TObject);
    procedure SpeedButtonItalicClick(Sender: TObject);
    procedure SpeedButtonUnderlineClick(Sender: TObject);
    procedure actVisibleExecute(Sender: TObject);
    procedure AboutToolbar1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure actDisableStylesExecute(Sender: TObject);
    procedure actDisableSoundsExecute(Sender: TObject);
    procedure actExitExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ToolbarForm: TToolbarForm;

implementation

{$R *.DFM}

procedure TToolbarForm.SpeedButtonNoteClick(Sender: TObject);
begin
  Beep;
end;

procedure TToolbarForm.SpeedButtonLeftClick(Sender: TObject);
begin
  Label1.Alignment := taLeftJustify;
end;

procedure TToolbarForm.SpeedButtonCenterClick(Sender: TObject);
begin
  Label1.Alignment := taCenter;
end;

procedure TToolbarForm.SpeedButtonRightClick(Sender: TObject);
begin
  Label1.Alignment := taRightJustify;
end;

procedure TToolbarForm.SpeedButtonBoldClick(Sender: TObject);
begin
  if SpeedButtonBold.Down then
    Label1.Font.Style := [fsBold]
  else
    Label1.Font.Style := [];
end;

procedure TToolbarForm.SpeedButtonItalicClick(Sender: TObject);
begin
  if SpeedButtonItalic.Down then
    Label1.Font.Style := [fsItalic]
  else
    Label1.Font.Style := [];
end;

procedure TToolbarForm.SpeedButtonUnderlineClick(Sender: TObject);
begin
  if SpeedButtonUnderline.Down then
    Label1.Font.Style := [fsUnderline]
  else
    Label1.Font.Style := [];
end;

procedure TToolbarForm.actVisibleExecute(Sender: TObject);
begin
  // hide or display the toolbar, setting the checkmark
  Panel1.Visible := not Panel1.Visible;
  Visible1.Checked := Panel1.Visible;
end;

procedure TToolbarForm.AboutToolbar1Click(Sender: TObject);
begin
  MessageDlg ('Toolbar example for "Mastering Delphi"' +
    Chr (13) +  'Written by Marco Cantù',
    mtInformation, [mbOk], 0);
end;

procedure TToolbarForm.FormCreate(Sender: TObject);
begin
  ComboBox1.Items := Screen.Fonts;
  // select the current font
  ComboBox1.ItemIndex :=
    ComboBox1.Items.IndexOf (Label1.Font.Name);
end;

procedure TToolbarForm.ComboBox1Change(Sender: TObject);
begin
  Label1.Font.Name :=
    ComboBox1.Items [ComboBox1.ItemIndex];
end;

procedure TToolbarForm.Edit1Change(Sender: TObject);
begin
  Label1.Font.Size := UpDown1.Position;
end;

procedure TToolbarForm.actDisableStylesExecute(Sender: TObject);
begin
  {disable or enable buttons and set menu text properly}
  if SpeedButtonBold.Enabled then
  begin
    SpeedButtonBold.Enabled := False;
    SpeedButtonItalic.Enabled := False;
    SpeedButtonUnderline.Enabled := False;
    actDisableStyles.Checked := True;
  end
  else
  begin
    SpeedButtonBold.Enabled := True;
    SpeedButtonItalic.Enabled := True;
    SpeedButtonUnderline.Enabled := True;
    actDisableStyles.Checked := False;
  end;
end;

procedure TToolbarForm.actDisableSoundsExecute(Sender: TObject);
begin
  // disable or enable button and set check mark
  SpeedButtonNote.Enabled := not SpeedButtonNote.Enabled;
  actDisableSounds.Checked := SpeedButtonNote.Enabled;
end;

procedure TToolbarForm.actExitExecute(Sender: TObject);
begin
  Close;
end;

end.

TOOLFORM.DFM

object ToolbarForm: TToolbarForm
  Left = 190
  Top = 141
  Width = 575
  Height = 359
  ActiveControl = ComboBox1
  Caption = 'ComboBar'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clBlack
  Font.Height = -12
  Font.Name = 'Arial'
  Font.Style = []
  Menu = MainMenu1
  OldCreateOrder = True
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 15
  object Label1: TLabel
    Left = 0
    Top = 36
    Width = 567
    Height = 277
    Align = alClient
    AutoSize = False
    Caption =
       'A caption with some sample text to show the effect of the speed ' +
      'buttons and of the combo box of the toolbar. You can replace thi' +
      's text with something more useful, for example a memo component.'
    Font.Charset = ANSI_CHARSET
    Font.Color = clBlack
    Font.Height = -16
    Font.Name = 'Arial'
    Font.Style = []
    ParentFont = False
    WordWrap = True
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 567
    Height = 36
    Align = alTop
    ParentShowHint = False
    PopupMenu = PopupMenu1
    ShowHint = True
    TabOrder = 0
    object SpeedButtonNote: TSpeedButton
      Left = 8
      Top = 5
      Width = 25
      Height = 25
      Hint = 'Play Note'
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333330000003330033333333333330000003300003330033333330000003300
        0003000033333300000033300003000003333300000033333303300003333300
        0000333333033333033333000000333333033333033333000000333333033333
        0333330000003333330333330333330000003333330333330333330000003333
        3300033303333300000033333303300003333300000033333300033303333300
        0000333333333000033333000000333333333333333333000000333333333333
        333333000000}
      OnClick = SpeedButtonNoteClick
    end
    object SpeedButtonBold: TSpeedButton
      Left = 120
      Top = 5
      Width = 25
      Height = 25
      Hint = 'Bold'
      AllowAllUp = True
      GroupIndex = 2
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333330000003333333333333333330000003333333333333333330000003333
        0000000033333300000033330000000003333300000033333003333003333300
        0000333330033330033333000000333330033300033333000000333330000000
        3333330000003333300000000333330000003333300333300333330000003333
        3003333003333300000033330000000003333300000033330000000033333300
        0000333333333333333333000000333333333333333333000000333333333333
        333333000000}
      OnClick = SpeedButtonBoldClick
    end
    object SpeedButtonItalic: TSpeedButton
      Left = 145
      Top = 5
      Width = 25
      Height = 25
      Hint = 'Italic'
      AllowAllUp = True
      GroupIndex = 2
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333330000003333333333333333330000003333333333333333330000003333
        3000000333333300000033333330033333333300000033333330033333333300
        0000333333300333333333000000333333330033333333000000333333330033
        3333330000003333333300333333330000003333333330033333330000003333
        3333300333333300000033333330000003333300000033333333333333333300
        0000333333333333333333000000333333333333333333000000333333333333
        333333000000}
      OnClick = SpeedButtonItalicClick
    end
    object SpeedButtonUnderline: TSpeedButton
      Left = 170
      Top = 5
      Width = 25
      Height = 25
      Hint = 'Underlined'
      AllowAllUp = True
      GroupIndex = 2
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333330000003333333333333333330000003333333333333333330000003333
        3000000003333300000033333000000003333300000033333333333333333300
        0000333333300030033333000000333333000000033333000000333333003000
        3333330000003333330033003333330000003333330033003333330000003333
        3300330033333300000033333000300033333300000033333333333333333300
        0000333333333333333333000000333333333333333333000000333333333333
        333333000000}
      OnClick = SpeedButtonUnderlineClick
    end
    object SpeedButtonLeft: TSpeedButton
      Left = 40
      Top = 5
      Width = 25
      Height = 25
      Hint = 'Left Align'
      GroupIndex = 1
      Down = True
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        333333000000330000000000000033000000330FFFFFFFFFFFF033000000330F
        0000000FFFF033000000330FFFFFFFFFFFF033000000330F000FFFFFFFF03300
        0000330FFFFFFFFFFFF033000000330F00000FFFFFF033000000330FFFFFFFFF
        FFF033000000330F000FFFFFFFF033000000330FFFFFFFFFFFF033000000330F
        00000000FFF033000000330FFFFFFFFFFFF033000000330F000000FFFFF03300
        0000330FFFFFFFFFFFF033000000330000000000000033000000333333333333
        333333000000}
      OnClick = SpeedButtonLeftClick
    end
    object SpeedButtonCenter: TSpeedButton
      Left = 65
      Top = 5
      Width = 25
      Height = 25
      Hint = 'Center'
      GroupIndex = 1
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        333333000000330000000000000033000000330FFFFFFFFFFFF033000000330F
        FF000000FFF033000000330FFFFFFFFFFFF033000000330FFFF0000FFFF03300
        0000330FFFFFFFFFFFF033000000330FFF000000FFF033000000330FFFFFFFFF
        FFF033000000330FFFFF00FFFFF033000000330FFFFFFFFFFFF033000000330F
        F00000000FF033000000330FFFFFFFFFFFF033000000330FFF000000FFF03300
        0000330FFFFFFFFFFFF033000000330000000000000033000000333333333333
        333333000000}
      OnClick = SpeedButtonCenterClick
    end
    object SpeedButtonRight: TSpeedButton
      Left = 90
      Top = 5
      Width = 25
      Height = 25
      Hint = 'Right Align'
      GroupIndex = 1
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        333333000000330000000000000033000000330FFFFFFFFFFFF033000000330F
        FFF0000000F033000000330FFFFFFFFFFFF033000000330FFFFFFFF000F03300
        0000330FFFFFFFFFFFF033000000330FFFFFF00000F033000000330FFFFFFFFF
        FFF033000000330FFFFFFFF000F033000000330FFFFFFFFFFFF033000000330F
        FF00000000F033000000330FFFFFFFFFFFF033000000330FFFFF000000F03300
        0000330FFFFFFFFFFFF033000000330000000000000033000000333333333333
        333333000000}
      OnClick = SpeedButtonRightClick
    end
    object Label2: TLabel
      Left = 208
      Top = 11
      Width = 27
      Height = 15
      Hint = 'Select Font'
      Caption = 'Font:'
    end
    object Label3: TLabel
      Left = 456
      Top = 11
      Width = 26
      Height = 15
      Hint = 'Font Size'
      Caption = 'Size:'
    end
    object ComboBox1: TComboBox
      Left = 238
      Top = 7
      Width = 201
      Height = 23
      Hint = 'Select Font'
      Style = csDropDownList
      ItemHeight = 15
      TabOrder = 0
      OnChange = ComboBox1Change
    end
    object Edit1: TEdit
      Left = 488
      Top = 8
      Width = 41
      Height = 23
      Hint = 'Font Size'
      MaxLength = 2
      TabOrder = 1
      Text = '12'
      OnChange = Edit1Change
    end
    object UpDown1: TUpDown
      Left = 529
      Top = 8
      Width = 15
      Height = 23
      Hint = 'Font Size'
      Associate = Edit1
      Min = 8
      Max = 72
      Increment = 2
      Position = 12
      TabOrder = 2
      Thousands = False
      Wrap = False
    end
  end
  object MainMenu1: TMainMenu
    Left = 40
    Top = 56
    object File1: TMenuItem
      Caption = '&File'
      object Exit1: TMenuItem
        Caption = 'E&xit'
      end
    end
    object Toolbar1: TMenuItem
      Caption = '&Toolbar'
      object Visible1: TMenuItem
        Action = actVisible
      end
      object DisableSound1: TMenuItem
        Action = actDisableSounds
      end
      object DisableStyles1: TMenuItem
        Action = actDisableStyles
      end
    end
    object Help1: TMenuItem
      Caption = '&Help'
      object AboutToolbar1: TMenuItem
        Caption = '&About Toolbar...'
        OnClick = AboutToolbar1Click
      end
    end
  end
  object PopupMenu1: TPopupMenu
    Left = 112
    Top = 56
    object Hide1: TMenuItem
      Action = actVisible
      Caption = '&Toolbar Visible'
    end
    object N1: TMenuItem
      Caption = '-'
    end
    object DisableSound2: TMenuItem
      Action = actDisableSounds
    end
    object DisableStyles2: TMenuItem
      Action = actDisableStyles
    end
  end
  object ActionList1: TActionList
    Left = 176
    Top = 56
    object actVisible: TAction
      Caption = '&Visible'
      ShortCut = 49238
      OnExecute = actVisibleExecute
    end
    object actDisableSounds: TAction
      Caption = 'Disable &Sounds'
      OnExecute = actDisableSoundsExecute
    end
    object actDisableStyles: TAction
      Caption = '&Disable Styles'
      OnExecute = actDisableStylesExecute
    end
    object actExit: TAction
      Caption = '&Exit'
      ShortCut = 32883
      OnExecute = actExitExecute
    end
  end
end


Copyright Marco Cantù 1998