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 MASTDET2

Project Structure


MASTDET2.DPR

program Mastdet2;

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)
    Table1: TTable;
    Table2: TTable;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    Table3: TTable;
    DataSource3: TDataSource;
    Table3EmpNo: TIntegerField;
    Table3LastName: TStringField;
    Table3FirstName: TStringField;
    Table3PhoneExt: TStringField;
    Table3HireDate: TDateTimeField;
    Table3Salary: TFloatField;
    Table2OrderNo: TFloatField;
    Table2CustNo: TFloatField;
    Table2SaleDate: TDateTimeField;
    Table2ShipDate: TDateTimeField;
    Table2EmpNo: TIntegerField;
    Table2ShipToContact: TStringField;
    Table2ShipToAddr1: TStringField;
    Table2ShipToAddr2: TStringField;
    Table2ShipToCity: TStringField;
    Table2ShipToState: TStringField;
    Table2ShipToZip: TStringField;
    Table2ShipToCountry: TStringField;
    Table2ShipToPhone: TStringField;
    Table2ShipVIA: TStringField;
    Table2PO: TStringField;
    Table2Terms: TStringField;
    Table2PaymentMethod: TStringField;
    Table2ItemsTotal: TCurrencyField;
    Table2TaxRate: TFloatField;
    Table2Freight: TCurrencyField;
    Table2AmountPaid: TCurrencyField;
    Table2Employee: TStringField;
    Table1CustNo: TFloatField;
    Table1Company: TStringField;
    Table1Addr1: TStringField;
    Table1Addr2: TStringField;
    Table1City: TStringField;
    Table1State: TStringField;
    Table1Zip: TStringField;
    Table1Country: TStringField;
    Table1Phone: TStringField;
    Table1FAX: TStringField;
    Table1TaxRate: TFloatField;
    Table1Contact: TStringField;
    Table1LastInvoiceDate: TDateTimeField;
    procedure DataModule1Create(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DataModule1: TDataModule1;

implementation

{$R *.DFM}

procedure TDataModule1.DataModule1Create(Sender: TObject);
begin
  Table3.Open;
  Table1.Open;
  Table2.Open;
end;

end.

MASTDETF.DFM

object Form2: TForm2
  Left = 205
  Top = 116
  Width = 596
  Height = 305
  ActiveControl = Panel1
  Caption = 'Master Detail with Lookup'
  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 = 588
    Height = 41
    Align = alTop
    TabOrder = 0
    object DBNavigator: TDBNavigator
      Left = 8
      Top = 8
      Width = 161
      Height = 25
      DataSource = DataModule1.DataSource1
      VisibleButtons = [nbFirst, nbPrior, nbNext, nbLast, nbPost, nbCancel, nbRefresh]
      Ctl3D = False
      ParentCtl3D = False
      TabOrder = 0
    end
  end
  object Panel2: TPanel
    Left = 0
    Top = 41
    Width = 588
    Height = 104
    Align = alTop
    BevelInner = bvLowered
    BorderWidth = 4
    Caption = 'Panel2'
    TabOrder = 1
    object ScrollBox: TScrollBox
      Left = 6
      Top = 6
      Width = 576
      Height = 92
      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
        DataField = 'Company'
        DataSource = DataModule1.DataSource1
        TabOrder = 0
      end
      object EditAddr: TDBEdit
        Left = 162
        Top = 21
        Width = 150
        Height = 21
        DataField = 'Addr1'
        DataSource = DataModule1.DataSource1
        TabOrder = 1
      end
      object EditAddr2: TDBEdit
        Left = 318
        Top = 21
        Width = 150
        Height = 21
        DataField = 'Addr2'
        DataSource = DataModule1.DataSource1
        TabOrder = 2
      end
      object EditCity: TDBEdit
        Left = 474
        Top = 21
        Width = 75
        Height = 21
        DataField = 'City'
        DataSource = DataModule1.DataSource1
        TabOrder = 3
      end
      object EditState: TDBEdit
        Left = 6
        Top = 65
        Width = 100
        Height = 21
        DataField = 'State'
        DataSource = DataModule1.DataSource1
        TabOrder = 4
      end
      object EditZip: TDBEdit
        Left = 112
        Top = 65
        Width = 50
        Height = 21
        DataField = 'Zip'
        DataSource = DataModule1.DataSource1
        TabOrder = 5
      end
      object EditCountry: TDBEdit
        Left = 168
        Top = 65
        Width = 145
        Height = 21
        DataField = 'Country'
        DataSource = DataModule1.DataSource1
        TabOrder = 6
      end
      object EditPhone: TDBEdit
        Left = 318
        Top = 65
        Width = 115
        Height = 21
        DataField = 'Phone'
        DataSource = DataModule1.DataSource1
        TabOrder = 7
      end
      object EditFAX: TDBEdit
        Left = 439
        Top = 65
        Width = 114
        Height = 21
        DataField = 'FAX'
        DataSource = DataModule1.DataSource1
        TabOrder = 8
      end
    end
  end
  object Panel3: TPanel
    Left = 0
    Top = 145
    Width = 588
    Height = 133
    Align = alClient
    BevelInner = bvLowered
    BorderWidth = 4
    Caption = 'Panel3'
    TabOrder = 2
    object DBGrid1: TDBGrid
      Left = 6
      Top = 6
      Width = 576
      Height = 121
      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 = 68
  Top = 134
  Height = 497
  Width = 750
  object Table1: TTable
    DatabaseName = 'DBDEMOS'
    TableName = 'customer.db'
    Left = 20
    Top = 13
    object Table1CustNo: TFloatField
      Alignment = taLeftJustify
      CustomConstraint = 'CustNo IS NOT NULL'
      ConstraintErrorMessage = 'CustNo cannot be blank'
      FieldName = 'CustNo'
      DisplayFormat = 'CN 0000'
      MaxValue = 9999
      MinValue = 1000
    end
    object Table1Company: TStringField
      CustomConstraint = 'X IS NOT NULL'
      ConstraintErrorMessage = 'Company Field has to have a value'
      FieldName = 'Company'
      Size = 30
    end
    object Table1Addr1: TStringField
      FieldName = 'Addr1'
      Size = 30
    end
    object Table1Addr2: TStringField
      FieldName = 'Addr2'
      Size = 30
    end
    object Table1City: TStringField
      FieldName = 'City'
      Size = 15
    end
    object Table1State: TStringField
      FieldName = 'State'
    end
    object Table1Zip: TStringField
      FieldName = 'Zip'
      Size = 10
    end
    object Table1Country: TStringField
      FieldName = 'Country'
    end
    object Table1Phone: TStringField
      FieldName = 'Phone'
      Size = 15
    end
    object Table1FAX: TStringField
      FieldName = 'FAX'
      Size = 15
    end
    object Table1TaxRate: TFloatField
      FieldName = 'TaxRate'
      DisplayFormat = '0.00%'
      MaxValue = 100
    end
    object Table1Contact: TStringField
      FieldName = 'Contact'
    end
    object Table1LastInvoiceDate: TDateTimeField
      FieldName = 'LastInvoiceDate'
    end
  end
  object Table2: TTable
    DatabaseName = 'DBDEMOS'
    IndexName = 'CustNo'
    MasterFields = 'CustNo'
    MasterSource = DataSource1
    TableName = 'orders.db'
    Left = 98
    Top = 13
    object Table2OrderNo: TFloatField
      FieldName = 'OrderNo'
    end
    object Table2CustNo: TFloatField
      FieldName = 'CustNo'
      Required = True
    end
    object Table2SaleDate: TDateTimeField
      FieldName = 'SaleDate'
    end
    object Table2ShipDate: TDateTimeField
      FieldName = 'ShipDate'
    end
    object Table2EmpNo: TIntegerField
      FieldName = 'EmpNo'
      Required = True
      Visible = False
    end
    object Table2Employee: TStringField
      FieldKind = fkLookup
      FieldName = 'Employee'
      LookupDataSet = Table3
      LookupKeyFields = 'EmpNo'
      LookupResultField = 'LastName'
      KeyFields = 'EmpNo'
      Size = 30
      Lookup = True
    end
    object Table2ShipToContact: TStringField
      FieldName = 'ShipToContact'
    end
    object Table2ShipToAddr1: TStringField
      FieldName = 'ShipToAddr1'
      Size = 30
    end
    object Table2ShipToAddr2: TStringField
      FieldName = 'ShipToAddr2'
      Size = 30
    end
    object Table2ShipToCity: TStringField
      FieldName = 'ShipToCity'
      Size = 15
    end
    object Table2ShipToState: TStringField
      FieldName = 'ShipToState'
    end
    object Table2ShipToZip: TStringField
      FieldName = 'ShipToZip'
      Size = 10
    end
    object Table2ShipToCountry: TStringField
      FieldName = 'ShipToCountry'
    end
    object Table2ShipToPhone: TStringField
      FieldName = 'ShipToPhone'
      Size = 15
    end
    object Table2ShipVIA: TStringField
      FieldName = 'ShipVIA'
      Size = 7
    end
    object Table2PO: TStringField
      FieldName = 'PO'
      Size = 15
    end
    object Table2Terms: TStringField
      FieldName = 'Terms'
      Size = 6
    end
    object Table2PaymentMethod: TStringField
      FieldName = 'PaymentMethod'
      Size = 7
    end
    object Table2ItemsTotal: TCurrencyField
      FieldName = 'ItemsTotal'
    end
    object Table2TaxRate: TFloatField
      FieldName = 'TaxRate'
    end
    object Table2Freight: TCurrencyField
      FieldName = 'Freight'
    end
    object Table2AmountPaid: TCurrencyField
      FieldName = 'AmountPaid'
    end
  end
  object DataSource1: TDataSource
    DataSet = Table1
    Left = 24
    Top = 64
  end
  object DataSource2: TDataSource
    DataSet = Table2
    Left = 101
    Top = 61
  end
  object Table3: TTable
    Active = True
    DatabaseName = 'DBDEMOS'
    IndexName = 'ByName'
    TableName = 'EMPLOYEE.DB'
    Left = 176
    Top = 16
    object Table3EmpNo: TIntegerField
      FieldName = 'EmpNo'
    end
    object Table3LastName: TStringField
      FieldName = 'LastName'
    end
    object Table3FirstName: TStringField
      FieldName = 'FirstName'
      Size = 15
    end
    object Table3PhoneExt: TStringField
      FieldName = 'PhoneExt'
      Size = 4
    end
    object Table3HireDate: TDateTimeField
      FieldName = 'HireDate'
    end
    object Table3Salary: TFloatField
      FieldName = 'Salary'
    end
  end
  object DataSource3: TDataSource
    DataSet = Table3
    Left = 176
    Top = 64
  end
end