Marco Web Center

[an error occurred while processing this directive]

Home: Code Repository: Mastering Delphi 5

Project DBDATES

Project Structure


DBDATES.DPR

program DbDates;

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

{$R *.RES}

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

DBDATESF.PAS

unit DbDatesF;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, Mask, DBCtrls, Db, DBTables, ExtCtrls,
  Grids, DBGrids, DBCGrids;

type
  TForm1 = class(TForm)
    Table1: TTable;
    DBEdit2: TDBEdit;
    DBNavigator1: TDBNavigator;
    Table1EventNo: TAutoIncField;
    Table1VenueNo: TIntegerField;
    Table1Event_Name: TStringField;
    Table1Event_Date: TDateField;
    Table1Event_Time: TTimeField;
    Table1Event_Description: TMemoField;
    Table1Ticket_price: TCurrencyField;
    Table1Event_Photo: TGraphicField;
    DBImage1: TDBImage;
    DBGrid1: TDBGrid;
    Label2: TLabel;
    DataSource1: TDataSource;
    MonthCalendar1: TMonthCalendar;
    procedure DataSource1DataChange(Sender: TObject; Field: TField);
    procedure MonthCalendar1Click(Sender: TObject);
    procedure DataSource1UpdateData(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  MonthCalendar1.Date := Table1Event_Date.Value;
end;

procedure TForm1.MonthCalendar1Click(Sender: TObject);
begin
  // disconnect handler
  DataSource1.OnDataChange := nil;
  // set table in edit mode
  Table1.Edit;
  // reconnect handler
  DataSource1.OnDataChange := DataSource1DataChange;
end;

procedure TForm1.DataSource1UpdateData(Sender: TObject);
begin
  Table1Event_Date.Value := MonthCalendar1.Date;
end;

end.

DBDATESF.DFM

object Form1: TForm1
  Left = 198
  Top = 112
  Width = 649
  Height = 440
  Caption = 'DbDates'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label2: TLabel
    Left = 40
    Top = 16
    Width = 28
    Height = 13
    Caption = 'Event'
  end
  object DBEdit2: TDBEdit
    Left = 40
    Top = 35
    Width = 161
    Height = 21
    DataField = 'Event_Name'
    DataSource = DataSource1
    TabOrder = 0
  end
  object DBNavigator1: TDBNavigator
    Left = 240
    Top = 24
    Width = 360
    Height = 33
    DataSource = DataSource1
    TabOrder = 1
  end
  object DBImage1: TDBImage
    Left = 40
    Top = 80
    Width = 161
    Height = 121
    DataField = 'Event_Photo'
    DataSource = DataSource1
    Stretch = True
    TabOrder = 3
  end
  object DBGrid1: TDBGrid
    Left = 240
    Top = 80
    Width = 361
    Height = 297
    DataSource = DataSource1
    TabOrder = 2
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
  end
  object MonthCalendar1: TMonthCalendar
    Left = 24
    Top = 224
    Width = 193
    Height = 153
    Date = 35933.7775719907
    ShowToday = False
    TabOrder = 4
    OnClick = MonthCalendar1Click
  end
  object Table1: TTable
    Active = True
    DatabaseName = 'DBDEMOS'
    TableName = 'EVENTS.DB'
    Left = 336
    Top = 8
    object Table1EventNo: TAutoIncField
      FieldName = 'EventNo'
    end
    object Table1VenueNo: TIntegerField
      DisplayWidth = 12
      FieldName = 'VenueNo'
    end
    object Table1Event_Name: TStringField
      DisplayWidth = 36
      FieldName = 'Event_Name'
      Size = 30
    end
    object Table1Event_Date: TDateField
      FieldName = 'Event_Date'
    end
    object Table1Event_Time: TTimeField
      FieldName = 'Event_Time'
    end
    object Table1Event_Description: TMemoField
      FieldName = 'Event_Description'
      BlobType = ftMemo
      Size = 100
    end
    object Table1Ticket_price: TCurrencyField
      DisplayWidth = 15
      FieldName = 'Ticket_price'
    end
    object Table1Event_Photo: TGraphicField
      FieldName = 'Event_Photo'
      BlobType = ftGraphic
    end
  end
  object DataSource1: TDataSource
    DataSet = Table1
    OnDataChange = DataSource1DataChange
    OnUpdateData = DataSource1UpdateData
    Left = 392
    Top = 8
  end
end