Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Mastering Delphi 6

Chapter 07 - Project Pages

Project Structure

Pages.dpr
program Pages;

uses
  Forms,
  PagesF in 'PagesF.pas' {Form1};

{$R *.RES}

        begin
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
PagesF.pas
unit PagesF;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ComCtrls, ImgList;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    ListBox1: TListBox;
    BitBtnPrevious: TBitBtn;
    BitBtnNext: TBitBtn;
    EditWidth: TEdit;
    UpDown1: TUpDown;
    Label1: TLabel;
    CheckBoxMultiLine: TCheckBox;
    CheckBoxVisible: TCheckBox;
    BitBtnApply: TBitBtn;
    Memo1: TMemo;
    Label2: TLabel;
    EditHeight: TEdit;
    UpDown2: TUpDown;
    Label3: TLabel;
    BitBtnChange: TBitBtn;
    ImageList1: TImageList;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    BitBtnAdd: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure BitBtnApplyClick(Sender: TObject);
    procedure BitBtnChangeClick(Sender: TObject);
    procedure BitBtnNextClick(Sender: TObject);
    procedure BitBtnPreviousClick(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure BitBtnAddClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  {fill the listbox and the memo
  with the names of the pages}
  for I := 0 to PageControl1.PageCount -1 do
  begin
    ListBox1.Items.Add (
      PageControl1.Pages [I].Caption);
    Memo1.Lines.Add (
      PageControl1.Pages [I].Caption);
  end;
  {set the initial width and height of tabs}
  EditWidth.Text := IntToStr (PageControl1.TabWidth);
  EditHeight.Text := IntToStr (PageControl1.TabHeight);
  {set the initial width and height of tabs}
  PageControl1.ActivePage := TabSheet1;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  PageControl1.ActivePage :=
    PageControl1.Pages [ListBox1.ItemIndex];
end;

procedure TForm1.BitBtnApplyClick(Sender: TObject);
begin
  // set tab width, height, and lines
  PageControl1.TabWidth := StrToInt (EditWidth.Text);
  PageControl1.TabHeight := StrToInt (EditHeight.Text);
  PageControl1.MultiLine := CheckBoxMultiLine.Checked;
  // show or hide the last tab
  TabSheet3.TabVisible := CheckBoxVisible.Checked;
  // set the tab position
  if RadioButton1.Checked then
    PageControl1.TabPosition := tpTop
  else
    PageControl1.TabPosition := tpLeft;
end;

procedure TForm1.BitBtnChangeClick(Sender: TObject);
var
  I: Integer;
begin
  if Memo1.Lines.Count = PageControl1.PageCount then
    for I := 0 to PageControl1.PageCount -1 do
      PageControl1.Pages [I].Caption := Memo1.Lines [I];
  BitBtnChange.Enabled := False;
end;

procedure TForm1.BitBtnNextClick(Sender: TObject);
begin
  // basic version:
  {PageControl1.SelectNextPage (True);}

  // special lookup version:
  PageControl1.ActivePage :=
    PageControl1.FindNextPage (
      PageControl1.ActivePage, True, False);
end;

procedure TForm1.BitBtnPreviousClick(Sender: TObject);
begin
  {select previous page}
  PageControl1.SelectNextPage (False);
end;

procedure TForm1.Memo1Change(Sender: TObject);
begin
  BitBtnChange.Enabled := True;
end;

procedure TForm1.BitBtnAddClick(Sender: TObject);
var
  strCaption: string;
  NewTabSheet: TTabSheet;
begin
  strCaption := 'New Tab';
  if InputQuery ('New Tab', 'Tab Caption', strCaption) then
  begin
    // add a new empty page to the control
    NewTabSheet := TTabSheet.Create (PageControl1);
    NewTabSheet.Visible := True;
    NewTabSheet.Caption := strCaption;
    NewTabSheet.PageControl := PageControl1;
    PageControl1.ActivePage := NewTabSheet;
    // add it to both lists
    Memo1.Lines.Add (strCaption);
    ListBox1.Items.Add (strCaption);
  end;
end;

end.
PagesF.dfm
object Form1: TForm1
  Left = 258
  Top = 117
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'Pages Test'
  ClientHeight = 276
  ClientWidth = 321
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  OnCreate = FormCreate
  DesignSize = (
    321
    276)
  PixelsPerInch = 96
  TextHeight = 13
  object PageControl1: TPageControl
    Left = 0
    Top = 0
    Width = 321
    Height = 276
    ActivePage = TabSheet1
    Align = alClient
    HotTrack = True
    Images = ImageList1
    TabIndex = 0
    TabOrder = 0
    object TabSheet1: TTabSheet
      Caption = 'Pages'
      DesignSize = (
        313
        247)
      object Label3: TLabel
        Left = 216
        Top = 16
        Width = 88
        Height = 65
        HelpType = htKeyword
        Anchors = [akTop, akRight]
        AutoSize = False
        Caption = 'Click on the listbox to change page'
        WordWrap = True
      end
      object ListBox1: TListBox
        Left = 16
        Top = 16
        Width = 193
        Height = 212
        Anchors = [akLeft, akTop, akRight, akBottom]
        ItemHeight = 13
        TabOrder = 0
        OnClick = ListBox1Click
      end
    end
    object TabSheet2: TTabSheet
      Caption = 'Tabs Size'
      ImageIndex = 1
      DesignSize = (
        313
        247)
      object Label1: TLabel
        Left = 24
        Top = 32
        Width = 58
        Height = 13
        HelpType = htKeyword
        Caption = 'Tabs &Width:'
        FocusControl = EditWidth
      end
      object Label2: TLabel
        Left = 24
        Top = 76
        Width = 61
        Height = 13
        HelpType = htKeyword
        Caption = 'Tabs &Height:'
        FocusControl = EditHeight
      end
      object EditWidth: TEdit
        Left = 108
        Top = 28
        Width = 65
        Height = 21
        TabOrder = 0
        Text = '0'
      end
      object UpDown1: TUpDown
        Left = 173
        Top = 28
        Width = 15
        Height = 21
        Associate = EditWidth
        Min = 0
        Max = 2000
        Position = 0
        TabOrder = 1
        Thousands = False
        Wrap = False
      end
      object CheckBoxMultiLine: TCheckBox
        Left = 24
        Top = 120
        Width = 97
        Height = 17
        Caption = '&Multi-Line Tabs'
        TabOrder = 2
      end
      object CheckBoxVisible: TCheckBox
        Left = 144
        Top = 120
        Width = 121
        Height = 17
        Caption = '&Last Tabs &Visible'
        Checked = True
        State = cbChecked
        TabOrder = 3
      end
      object BitBtnApply: TBitBtn
        Left = 228
        Top = 26
        Width = 75
        Height = 26
        Anchors = [akTop, akRight]
        Caption = '&Apply'
        ModalResult = 4
        TabOrder = 4
        OnClick = BitBtnApplyClick
        Glyph.Data = {
          76010000424D7601000000000000760000002800000020000000100000000100
          04000000000000010000120B0000120B00001000000000000000000000000000
          800000800000008080008000000080008000808000007F7F7F00BFBFBF000000
          FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00555555555555
          555555555555555555555555555555555555555555FF55555555555559055555
          55555555577FF5555555555599905555555555557777F5555555555599905555
          555555557777FF5555555559999905555555555777777F555555559999990555
          5555557777777FF5555557990599905555555777757777F55555790555599055
          55557775555777FF5555555555599905555555555557777F5555555555559905
          555555555555777FF5555555555559905555555555555777FF55555555555579
          05555555555555777FF5555555555557905555555555555777FF555555555555
          5990555555555555577755555555555555555555555555555555}
        NumGlyphs = 2
      end
      object EditHeight: TEdit
        Left = 108
        Top = 72
        Width = 65
        Height = 21
        TabOrder = 5
        Text = '0'
      end
      object UpDown2: TUpDown
        Left = 173
        Top = 72
        Width = 15
        Height = 21
        Associate = EditHeight
        Min = 0
        Max = 2000
        Position = 0
        TabOrder = 6
        Thousands = False
        Wrap = False
      end
      object GroupBox1: TGroupBox
        Left = 24
        Top = 150
        Width = 89
        Height = 69
        Caption = 'Tab Position'
        TabOrder = 7
        object RadioButton1: TRadioButton
          Left = 8
          Top = 20
          Width = 49
          Height = 17
          Caption = 'Top'
          Checked = True
          TabOrder = 0
          TabStop = True
        end
        object RadioButton2: TRadioButton
          Left = 8
          Top = 43
          Width = 49
          Height = 17
          Caption = 'Left'
          TabOrder = 1
        end
      end
    end
    object TabSheet3: TTabSheet
      Caption = 'Tabs Text'
      ImageIndex = 2
      DesignSize = (
        313
        247)
      object Memo1: TMemo
        Left = 16
        Top = 16
        Width = 193
        Height = 213
        Anchors = [akLeft, akTop, akRight, akBottom]
        TabOrder = 0
        OnChange = Memo1Change
      end
      object BitBtnChange: TBitBtn
        Left = 228
        Top = 18
        Width = 75
        Height = 26
        Anchors = [akTop, akRight]
        Caption = '&Change'
        Enabled = False
        ModalResult = 4
        TabOrder = 1
        OnClick = BitBtnChangeClick
        Glyph.Data = {
          76010000424D7601000000000000760000002800000020000000100000000100
          04000000000000010000120B0000120B00001000000000000000000000000000
          800000800000008080008000000080008000808000007F7F7F00BFBFBF000000
          FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00555555555555
          555555555555555555555555555555555555555555FF55555555555559055555
          55555555577FF5555555555599905555555555557777F5555555555599905555
          555555557777FF5555555559999905555555555777777F555555559999990555
          5555557777777FF5555557990599905555555777757777F55555790555599055
          55557775555777FF5555555555599905555555555557777F5555555555559905
          555555555555777FF5555555555559905555555555555777FF55555555555579
          05555555555555777FF5555555555557905555555555555777FF555555555555
          5990555555555555577755555555555555555555555555555555}
        NumGlyphs = 2
      end
      object BitBtnAdd: TBitBtn
        Left = 229
        Top = 52
        Width = 74
        Height = 26
        Caption = 'Add Page...'
        TabOrder = 2
        OnClick = BitBtnAddClick
      end
    end
  end
  object BitBtnPrevious: TBitBtn
    Left = 232
    Top = 232
    Width = 75
    Height = 26
    Anchors = [akRight, akBottom]
    Caption = '&Previous'
    TabOrder = 1
    OnClick = BitBtnPreviousClick
    Glyph.Data = {
      76010000424D7601000000000000760000002800000020000000100000000100
      04000000000000010000120B0000120B00001000000000000000000000000000
      800000800000008080008000000080008000808000007F7F7F00BFBFBF000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
      3333333333333333333333333333333333333333333333333333333333333333
      3333333333333FF3333333333333003333333333333F77F33333333333009033
      333333333F7737F333333333009990333333333F773337FFFFFF330099999000
      00003F773333377777770099999999999990773FF33333FFFFF7330099999000
      000033773FF33777777733330099903333333333773FF7F33333333333009033
      33333333337737F3333333333333003333333333333377333333333333333333
      3333333333333333333333333333333333333333333333333333333333333333
      3333333333333333333333333333333333333333333333333333}
    NumGlyphs = 2
  end
  object BitBtnNext: TBitBtn
    Left = 232
    Top = 200
    Width = 75
    Height = 26
    Anchors = [akRight, akBottom]
    Caption = '&Next'
    Default = True
    TabOrder = 2
    OnClick = BitBtnNextClick
    Glyph.Data = {
      76010000424D7601000000000000760000002800000020000000100000000100
      04000000000000010000120B0000120B00001000000000000000000000000000
      800000800000008080008000000080008000808000007F7F7F00BFBFBF000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
      3333333333333333333333333333333333333333333333333333333333333333
      3333333333333333333333333333333333333333333FF3333333333333003333
      3333333333773FF3333333333309003333333333337F773FF333333333099900
      33333FFFFF7F33773FF30000000999990033777777733333773F099999999999
      99007FFFFFFF33333F7700000009999900337777777F333F7733333333099900
      33333333337F3F77333333333309003333333333337F77333333333333003333
      3333333333773333333333333333333333333333333333333333333333333333
      3333333333333333333333333333333333333333333333333333}
    Layout = blGlyphRight
    NumGlyphs = 2
  end
  object ImageList1: TImageList
    Left = 44
    Top = 56
    Bitmap = {
      494C010103000500040010001000FFFFFFFFFF00FFFFFFFFFFFFFFFF424D3600
      0000000000003600000028000000400000002000000001001000000000000010
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000000000000000000000000FF7F0000
      FF7F0000000000000000FF7FFF7FFF7F00000000000000000000000000000000
      FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000000000FF7F0000FF7F0000
      FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000
      FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      FF7F000000000000000000000000FF7F00000000000000000000000000000000
      FF7F00000000FF7F000000000000FF7F00000000000000000000000000001042
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000
      FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000010420000
      0000000000000000000010420000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      FF7F000000000000000000000000FF7F0000000000000000007C000000000000
      FF7F0000186300000000FF7F0000FF7F00000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F0000000000000000007C007C00000000
      FF7FFF7FFF7FFF7FFF7FFF7FFF7FFF7F00000000000000000000000000000000
      1042000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      FF7F000000000000FF7FFF7FFF7FFF7F00000000007C007C007C007C007C0000
      FF7F00000000FF7F000000000000000000000000000000000000000000001042
      0000000000000000104200000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      FF7FFF7FFF7FFF7FFF7F00000000000000000000007C007C007C007C007C007C
      0000FF7FFF7FFF7F0000FF7FFF7F000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      FF7F00000000FF7FFF7F0000FF7F000000000000007C007C007C007C007C007C
      007C00001863FF7F0000FF7F0000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      FF7FFF7FFF7FFF7FFF7F00000000000000000000007C007C007C007C007C007C
      0000FF7FFF7FFF7F000000000000000000000000000000000000000000000000
      1042000000001042000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F0000FF7F0000
      0000000000000000000000000000000000000000007C007C007C007C007C0000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F0000FF7F000000000000
      000000000000000000000000000000000000000000000000007C007C00000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000FF7F00000000000000000000
      000000000000000000000000000000000000000000000000007C000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000424D3E000000000000003E000000
      2800000040000000200000000100010000000000000100000000000000000000
      000000000000000000000000FFFFFF0000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000FC00FFFFFFFF0000F000FC00FFFF0000
      C000FC00F18300000000FC00FBC700000000FC00F9C700000000EC00F8070000
      0000E400FD8F00000000E000FC8F000000000000FC8F000000000001FE1F0000
      00010003FE1F000000030007FE1F00000007000FFF3F0000001FE3FFFF7F0000
      007FE7FFFFFF000001FFEFFFFFFF0000}
  end
end