Marco's Web Center

Menu for Development

Site Menu
Object Pascal Handbook
Delphi Handbooks Collection
Mastering Borland Delphi 2005
(Old) White Papers
(Old)Tools
(Old) Conferences

My Other Sites
Italian Site (www.marcocantu.it)
the delphi search

Spirit of delphi

Advertising
Home My Blog Books Object Pascal Marco

Home: Code Repository: Mastering Delphi 5

Project FRAMETAB

Project Structure


FRAMETAB.DPR

program FrameTab;

uses
  Forms,
  TabForm in 'TabForm.pas' {Form1},
  Frame2u in 'Frame2u.pas' {Frame2: TFrame},
  Frame3u in 'Frame3u.pas' {Frame3: TFrame};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

TABFORM.PAS

unit TabForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Frame2u, Frame3u, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Tab: TTabControl;
    procedure TabChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    procedure ShowFrame (FrameName: string);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

type
  TFrameClass = class of TFrame;

procedure TForm1.ShowFrame(FrameName: string);
var
  Frame: TFrame;
  FrameClass: TFrameClass;
begin
  Frame := FindComponent (FrameName + '1') as TFrame;
  if not Assigned (Frame) then
  begin
    FrameClass := TFrameClass (FindClass ('T' + FrameName));
    Frame := FrameClass.Create (Self);
    Frame.Parent := Tab;
    Frame.Visible := True;
    Frame.Name := FrameName + '1';
  end;
  Frame.BringToFront;
end;

procedure TForm1.TabChange(Sender: TObject);
begin
  ShowFrame (Tab.Tabs [Tab.TabIndex]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ShowFrame (Tab.Tabs [Tab.TabIndex]);
end;

end.

FRAME2U.PAS

unit Frame2u;

interface

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

type
  TFrame2 = class(TFrame)
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    Button1: TButton;
    Button2: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

{$R *.DFM}

initialization
  RegisterClass (TFrame2);

end.

FRAME3U.PAS

unit Frame3u;

interface

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

type
  TFrame3 = class(TFrame)
    ListBox1: TListBox;
    btnAdd: TButton;
    btnDelete: TButton;
    LabelFile: TLabel;
    Label1: TLabel;
    btnSave: TButton;
    procedure btnAddClick(Sender: TObject);
    procedure btnDeleteClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
  private
    { Private declarations }
  public
    procedure CreateWnd; override;
  end;

implementation

{$R *.DFM}

procedure TFrame3.btnAddClick(Sender: TObject);
var
  strNew: string;
begin
  if InputQuery ('Enter new item', 'Text', strNew) then
    ListBox1.Items.Add (strNew);
end;

procedure TFrame3.btnDeleteClick(Sender: TObject);
begin
  if ListBox1.ItemIndex >= 0 then
    ListBox1.Items.Delete (ListBox1.ItemIndex);
end;

procedure TFrame3.CreateWnd;
begin
  inherited;
  // load data
  ListBox1.Items.LoadFromFile (LabelFile.Caption);
end;

procedure TFrame3.btnSaveClick(Sender: TObject);
begin
  ListBox1.Items.SaveToFile (LabelFile.Caption);
end;

initialization
  RegisterClass (TFrame3);

end.

TABFORM.DFM

object Form1: TForm1
  Left = 213
  Top = 186
  Width = 380
  Height = 357
  Caption = 'Frame Pages'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 194
    Top = 297
    Width = 75
    Height = 25
    Anchors = [akRight, akBottom]
    Caption = 'Button1'
    TabOrder = 0
  end
  object Button2: TButton
    Left = 282
    Top = 297
    Width = 75
    Height = 25
    Anchors = [akRight, akBottom]
    Caption = 'Button2'
    TabOrder = 1
  end
  object Tab: TTabControl
    Left = 0
    Top = 0
    Width = 372
    Height = 283
    Anchors = [akLeft, akTop, akRight, akBottom]
    TabOrder = 2
    Tabs.Strings = (
      'Frame2'
      'Frame3')
    TabIndex = 0
    OnChange = TabChange
  end
end

FRAME2U.DFM

object Frame2: TFrame2
  Left = 0
  Top = 0
  Width = 443
  Height = 277
  Align = alClient
  TabOrder = 0
  object CheckBox1: TCheckBox
    Left = 24
    Top = 24
    Width = 97
    Height = 17
    Caption = 'CheckBox1'
    TabOrder = 0
  end
  object CheckBox2: TCheckBox
    Left = 24
    Top = 56
    Width = 97
    Height = 17
    Caption = 'CheckBox2'
    TabOrder = 1
  end
  object CheckBox3: TCheckBox
    Left = 24
    Top = 88
    Width = 97
    Height = 17
    Caption = 'CheckBox3'
    TabOrder = 2
  end
  object CheckBox4: TCheckBox
    Left = 24
    Top = 120
    Width = 97
    Height = 17
    Caption = 'CheckBox4'
    TabOrder = 3
  end
  object CheckBox5: TCheckBox
    Left = 24
    Top = 152
    Width = 97
    Height = 17
    Caption = 'CheckBox5'
    TabOrder = 4
  end
  object Button1: TButton
    Left = 168
    Top = 32
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 5
  end
  object Button2: TButton
    Left = 168
    Top = 72
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 6
  end
end

FRAME3U.DFM

object Frame3: TFrame3
  Left = 0
  Top = 0
  Width = 443
  Height = 277
  Align = alClient
  TabOrder = 0
  object LabelFile: TLabel
    Left = 40
    Top = 16
    Width = 39
    Height = 13
    Caption = 'List.txt'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object Label1: TLabel
    Left = 16
    Top = 16
    Width = 19
    Height = 13
    Caption = 'File:'
  end
  object ListBox1: TListBox
    Left = 16
    Top = 32
    Width = 169
    Height = 209
    ItemHeight = 13
    TabOrder = 0
  end
  object btnAdd: TButton
    Left = 200
    Top = 32
    Width = 75
    Height = 25
    Caption = '&Add'
    TabOrder = 1
    OnClick = btnAddClick
  end
  object btnDelete: TButton
    Left = 200
    Top = 64
    Width = 75
    Height = 25
    Caption = '&Delete'
    TabOrder = 2
    OnClick = btnDeleteClick
  end
  object btnSave: TButton
    Left = 200
    Top = 96
    Width = 75
    Height = 25
    Caption = '&Save'
    TabOrder = 3
    OnClick = btnSaveClick
  end
end