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 6

Chapter 13 - Project MastDet

Project Structure

MastDet.dpr
program Mastdet;

uses
  Forms,
  MastdetF in 'MastdetF.pas' {Form2},
  MdData in 'MdData.pas' {DataModule1: TDataModule};

{$R *.RES}

begin
  Application.CreateForm(TForm2, Form2);
  Application.CreateForm(TDataModule1, DataModule1);
  Application.Run;
end.
MastdetF.pas
unit MastdetF;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  StdCtrls, Forms, DBCtrls, DB, DBGrids, DBTables, Grids, Mask, ExtCtrls;

type
  TForm2 = class(TForm)
    ScrollBox: TScrollBox;
    Label1: TLabel;
    EditCompany: TDBEdit;
    Label2: TLabel;
    EditAddr: TDBEdit;
    Label3: TLabel;
    EditAddr2: TDBEdit;
    Label4: TLabel;
    EditCity: TDBEdit;
    Label5: TLabel;
    EditState: TDBEdit;
    Label6: TLabel;
    EditZip: TDBEdit;
    Label7: TLabel;
    EditCountry: TDBEdit;
    Label8: TLabel;
    EditPhone: TDBEdit;
    Label9: TLabel;
    EditFAX: TDBEdit;
    DBGrid1: TDBGrid;
    DBNavigator: TDBNavigator;
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form2: TForm2;

implementation

uses MdData;

{$R *.DFM}

end.
MdData.pas
unit MdData;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables;

type
  TDataModule1 = class(TDataModule)
    TableCust: TTable;
    TableOrd: TTable;
    dsCust: TDataSource;
    dsOrd: TDataSource;
    procedure DataModule1Create(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DataModule1: TDataModule1;

implementation

{$R *.DFM}

procedure TDataModule1.DataModule1Create(Sender: TObject);
begin
  TableCust.Open;
  TableOrd.Open;
end;

end.
MastdetF.dfm
object Form2: TForm2
  Left = 202
  Top = 122
  Width = 581
  Height = 335
  ActiveControl = Panel1
  Caption = 'Master Detail'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 573
    Height = 41
    Align = alTop
    TabOrder = 0
    object DBNavigator: TDBNavigator
      Left = 8
      Top = 8
      Width = 240
      Height = 25
      DataSource = DataModule1.DataSource1
      Ctl3D = False
      ParentCtl3D = False
      TabOrder = 0
    end
  end
  object Panel2: TPanel
    Left = 0
    Top = 41
    Width = 573
    Height = 112
    Align = alTop
    BevelInner = bvLowered
    BorderWidth = 4
    Caption = 'Panel2'
    TabOrder = 1
    object ScrollBox: TScrollBox
      Left = 6
      Top = 6
      Width = 561
      Height = 100
      HorzScrollBar.Margin = 6
      VertScrollBar.Margin = 6
      Align = alClient
      BorderStyle = bsNone
      TabOrder = 0
      object Label1: TLabel
        Left = 6
        Top = 6
        Width = 44
        Height = 13
        Caption = 'Company'
        FocusControl = EditCompany
      end
      object Label2: TLabel
        Left = 162
        Top = 6
        Width = 28
        Height = 13
        Caption = 'Addr1'
        FocusControl = EditAddr
      end
      object Label3: TLabel
        Left = 318
        Top = 6
        Width = 28
        Height = 13
        Caption = 'Addr2'
        FocusControl = EditAddr2
      end
      object Label4: TLabel
        Left = 474
        Top = 6
        Width = 17
        Height = 13
        Caption = 'City'
        FocusControl = EditCity
      end
      object Label5: TLabel
        Left = 6
        Top = 50
        Width = 25
        Height = 13
        Caption = 'State'
        FocusControl = EditState
      end
      object Label6: TLabel
        Left = 112
        Top = 50
        Width = 15
        Height = 13
        Caption = 'Zip'
        FocusControl = EditZip
      end
      object Label7: TLabel
        Left = 168
        Top = 50
        Width = 36
        Height = 13
        Caption = 'Country'
        FocusControl = EditCountry
      end
      object Label8: TLabel
        Left = 318
        Top = 50
        Width = 31
        Height = 13
        Caption = 'Phone'
        FocusControl = EditPhone
      end
      object Label9: TLabel
        Left = 439
        Top = 50
        Width = 20
        Height = 13
        Caption = 'FAX'
        FocusControl = EditFAX
      end
      object EditCompany: TDBEdit
        Left = 6
        Top = 21
        Width = 150
        Height = 21
        Color = clWindow
        DataField = 'Company'
        DataSource = DataModule1.DataSource1
        TabOrder = 0
      end
      object EditAddr: TDBEdit
        Left = 162
        Top = 21
        Width = 150
        Height = 21
        Color = clWindow
        DataField = 'Addr1'
        DataSource = DataModule1.DataSource1
        TabOrder = 1
      end
      object EditAddr2: TDBEdit
        Left = 318
        Top = 21
        Width = 150
        Height = 21
        Color = clWindow
        DataField = 'Addr2'
        DataSource = DataModule1.DataSource1
        TabOrder = 2
      end
      object EditCity: TDBEdit
        Left = 474
        Top = 21
        Width = 75
        Height = 21
        Color = clWindow
        DataField = 'City'
        DataSource = DataModule1.DataSource1
        TabOrder = 3
      end
      object EditState: TDBEdit
        Left = 6
        Top = 65
        Width = 100
        Height = 21
        Color = clWindow
        DataField = 'State'
        DataSource = DataModule1.DataSource1
        TabOrder = 4
      end
      object EditZip: TDBEdit
        Left = 112
        Top = 65
        Width = 50
        Height = 21
        Color = clWindow
        DataField = 'Zip'
        DataSource = DataModule1.DataSource1
        TabOrder = 5
      end
      object EditCountry: TDBEdit
        Left = 168
        Top = 65
        Width = 145
        Height = 21
        Color = clWindow
        DataField = 'Country'
        DataSource = DataModule1.DataSource1
        TabOrder = 6
      end
      object EditPhone: TDBEdit
        Left = 318
        Top = 65
        Width = 115
        Height = 21
        Color = clWindow
        DataField = 'Phone'
        DataSource = DataModule1.DataSource1
        TabOrder = 7
      end
      object EditFAX: TDBEdit
        Left = 439
        Top = 65
        Width = 114
        Height = 21
        Color = clWindow
        DataField = 'FAX'
        DataSource = DataModule1.DataSource1
        TabOrder = 8
      end
    end
  end
  object Panel3: TPanel
    Left = 0
    Top = 153
    Width = 573
    Height = 155
    Align = alClient
    BevelInner = bvLowered
    BorderWidth = 4
    Caption = 'Panel3'
    TabOrder = 2
    object DBGrid1: TDBGrid
      Left = 6
      Top = 6
      Width = 561
      Height = 143
      Align = alClient
      BorderStyle = bsNone
      DataSource = DataModule1.DataSource2
      TabOrder = 0
      TitleFont.Charset = DEFAULT_CHARSET
      TitleFont.Color = clBlack
      TitleFont.Height = -11
      TitleFont.Name = 'MS Sans Serif'
      TitleFont.Style = []
    end
  end
end
MdData.dfm
object DataModule1: TDataModule1
  OldCreateOrder = False
  OnCreate = DataModule1Create
  Left = 282
  Top = 311
  Height = 323
  Width = 472
  object TableCust: TTable
    DatabaseName = 'DBDEMOS'
    TableName = 'customer.db'
    Left = 20
    Top = 13
  end
  object TableOrd: TTable
    DatabaseName = 'DBDEMOS'
    IndexName = 'CustNo'
    MasterFields = 'CustNo'
    MasterSource = dsCust
    TableName = 'orders.db'
    Left = 82
    Top = 13
  end
  object dsCust: TDataSource
    DataSet = TableCust
    Left = 32
    Top = 64
  end
  object dsOrd: TDataSource
    DataSet = TableOrd
    Left = 93
    Top = 69
  end
end