Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Mastering Delphi 5

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
  PixelsPerInch = 96
  TextHeight = 13
  object PageControl1: TPageControl
    Left = 0
    Top = 0
    Width = 321
    Height = 276
    ActivePage = TabSheet1
    Align = alClient
    HotTrack = True
    Images = ImageList1
    MultiLine = True
    ScrollOpposite = True
    TabOrder = 0
    object TabSheet1: TTabSheet
      Caption = 'Pages'
      object Label3: TLabel
        Left = 216
        Top = 16
        Width = 88
        Height = 65
        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 = 213
        Anchors = [akLeft, akTop, akRight, akBottom]
        ItemHeight = 13
        TabOrder = 0
        OnClick = ListBox1Click
      end
    end
    object TabSheet2: TTabSheet
      Caption = 'Tabs Size'
      ImageIndex = 1
      object Label1: TLabel
        Left = 24
        Top = 32
        Width = 58
        Height = 13
        Caption = 'Tabs &Width:'
        FocusControl = EditWidth
      end
      object Label2: TLabel
        Left = 24
        Top = 76
        Width = 61
        Height = 13
        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
      object Memo1: TMemo
        Left = 16
        Top = 16
        Width = 193
        Height = 214
        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 = {
      3607000003000000424D36070000000000003604000028000000300000001000
      0000010008000000000000030000000000000000000000010000000000000000
      0000000080000080000000808000800000008000800080800000C0C0C000C0DC
      C000F0CAA6000000000000000000000000000000000000000000000000000000
      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
      00000000000000000000000000000000000000000000F0FBFF00A4A0A0008080
      80000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000FF00FF00000000FFFFFF0000000000000000FFFFFFFFFFFFFFFF000000
      0000000000000000000000000000000000FF00FF00FFFFFFFFFFFFFFFF000000
      0000000000FFFFFFFFFFFFFFFF000000000000000000000000000000000000FF
      00FF00FF00FF000000000000FF0000000000000000FF0000FF000000FF000000
      00000000F800000000000000000000FF00FF00FF00FFFFFFFFFFFFFFFF000000
      0000000000FFFFFFFFFFFFFFFF000000000000F8000000000000F800000000FF
      00FF00FF00FF000000000000FF00000000F9000000FF00070000FF00FF000000
      000000000000000000000000000000FF00FF00FF00FFFFFFFFFFFFFFFF000000
      00F9F90000FFFFFFFFFFFFFFFF0000000000000000F8000000000000000000FF
      00FF00FF00FF000000FFFFFFFF0000F9F9F9F9F900FF0000FF00000000000000
      00000000F800000000F80000000000FF00FF00FF00FFFFFFFFFF0000000000F9
      F9F9F9F9F900FFFFFF00FFFF00000000000000000000000000000000000000FF
      00FF00FF00FF0000FFFF00FF000000F9F9F9F9F9F9F90007FF00FF0000000000
      000000000000000000000000000000FF00FF00FF00FFFFFFFFFF0000000000F9
      F9F9F9F9F900FFFFFF000000000000000000000000F80000F8000000000000FF
      00FF00FF0000000000000000000000F9F9F9F9F9000000000000000000000000
      000000000000000000000000000000FF00FF0000000000000000000000000000
      00F9F900000000000000000000000000000000000000000000000000000000FF
      0000000000000000000000000000000000F90000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000000000000000000000424D
      BE000000000000003E0000002800000030000000100000000100010000000000
      800000000000000000000000020000000000000000000000FFFFFF00FC00FFFF
      FFFFC281F000FC00FFFF6A00C000FC00F1837D010000FC00FBC702000000FC00
      F9C782020000EC00F80773010000E400FD8F82020000E000FC8F960100000000
      FC8F080000000001FE1F890100010003FE1F2B0200030007FE1F02000007000F
      FF3F8202001FE3FFFF7F00A0007FE7FFFFFFC28101FFEFFFFFFF00F0}
  end
end