Marco Web Center |
|
Chapter 13 - Project NullDates |
Project Structure |
NullDates.dpr |
program nulldates; uses Forms, NullDatesForm in 'NullDatesForm.pas' {Form1}; {$R *.RES} begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. |
NullDatesForm.pas |
unit NullDatesForm; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Db, StdCtrls, Mask, DBCtrls, DBTables, ExtCtrls, Grids, DBGrids; type TForm1 = class(TForm) Table1: TTable; Table1OrderNo: TFloatField; Table1CustNo: TFloatField; Table1SaleDate: TDateTimeField; Table1ShipDate: TDateTimeField; Table1EmpNo: TIntegerField; Table1ShipToContact: TStringField; Table1ShipToAddr1: TStringField; Table1ShipToAddr2: TStringField; Table1ShipToCity: TStringField; Table1ShipToState: TStringField; Table1ShipToZip: TStringField; Table1ShipToCountry: TStringField; Table1ShipToPhone: TStringField; Table1ShipVIA: TStringField; Table1PO: TStringField; Table1Terms: TStringField; Table1PaymentMethod: TStringField; Table1ItemsTotal: TCurrencyField; Table1TaxRate: TFloatField; Table1Freight: TCurrencyField; Table1AmountPaid: TCurrencyField; Label1: TLabel; DBEdit1: TDBEdit; DataSource1: TDataSource; Label2: TLabel; DBEdit2: TDBEdit; Label3: TLabel; DBEdit3: TDBEdit; Label4: TLabel; DBEdit4: TDBEdit; Label5: TLabel; DBEdit5: TDBEdit; DBNavigator1: TDBNavigator; DBGrid1: TDBGrid; procedure Table1ShipDateGetText(Sender: TField; var Text: String; DisplayText: Boolean); procedure Table1ShipDateSetText(Sender: TField; const Text: String); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Table1ShipDateGetText(Sender: TField; var Text: String; DisplayText: Boolean); begin if Sender.IsNull then Text := '<undefined>' else Text := Sender.AsString; end; procedure TForm1.Table1ShipDateSetText(Sender: TField; const Text: String); begin if Text = '' then Sender.Clear else Sender.AsString := Text; end; end. |
NullDatesForm.dfm |
object Form1: TForm1 Left = 192 Top = 107 Width = 742 Height = 292 Caption = 'Null Dates' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel Left = 48 Top = 48 Width = 40 Height = 13 Caption = 'OrderNo' FocusControl = DBEdit1 end object Label2: TLabel Left = 48 Top = 88 Width = 35 Height = 13 Caption = 'CustNo' FocusControl = DBEdit2 end object Label3: TLabel Left = 48 Top = 128 Width = 44 Height = 13 Caption = 'SaleDate' FocusControl = DBEdit3 end object Label4: TLabel Left = 48 Top = 168 Width = 44 Height = 13 Caption = 'ShipDate' FocusControl = DBEdit4 end object Label5: TLabel Left = 48 Top = 208 Width = 35 Height = 13 Caption = 'EmpNo' FocusControl = DBEdit5 end object DBEdit1: TDBEdit Left = 48 Top = 64 Width = 64 Height = 21 Color = clWindow DataField = 'OrderNo' DataSource = DataSource1 TabOrder = 0 end object DBEdit2: TDBEdit Left = 48 Top = 104 Width = 64 Height = 21 Color = clWindow DataField = 'CustNo' DataSource = DataSource1 TabOrder = 1 end object DBEdit3: TDBEdit Left = 48 Top = 144 Width = 169 Height = 21 Color = clWindow DataField = 'SaleDate' DataSource = DataSource1 TabOrder = 2 end object DBEdit4: TDBEdit Left = 48 Top = 184 Width = 169 Height = 21 Color = clWindow DataField = 'ShipDate' DataSource = DataSource1 TabOrder = 3 end object DBEdit5: TDBEdit Left = 48 Top = 224 Width = 64 Height = 21 Color = clWindow DataField = 'EmpNo' DataSource = DataSource1 TabOrder = 4 end object DBNavigator1: TDBNavigator Left = 16 Top = 16 Width = 240 Height = 25 DataSource = DataSource1 TabOrder = 5 end object DBGrid1: TDBGrid Left = 272 Top = 16 Width = 449 Height = 225 DataSource = DataSource1 TabOrder = 6 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clWindowText TitleFont.Height = -11 TitleFont.Name = 'MS Sans Serif' TitleFont.Style = [] end object Table1: TTable Active = True DatabaseName = 'DBDEMOS' TableName = 'orders.db' Left = 200 Top = 56 object Table1OrderNo: TFloatField FieldName = 'OrderNo' DisplayFormat = '''#''0000' end object Table1CustNo: TFloatField Alignment = taLeftJustify CustomConstraint = 'CustNo IS NOT NULL' ConstraintErrorMessage = 'CustNo cannot be blank' FieldName = 'CustNo' Required = True DisplayFormat = 'CN 0000' MaxValue = 9999 MinValue = 1000 end object Table1SaleDate: TDateTimeField FieldName = 'SaleDate' end object Table1ShipDate: TDateTimeField FieldName = 'ShipDate' OnGetText = Table1ShipDateGetText OnSetText = Table1ShipDateSetText end object Table1EmpNo: TIntegerField CustomConstraint = 'Value > 0' ConstraintErrorMessage = 'EmpNo cannot be 0 or negative' FieldName = 'EmpNo' Required = True DisplayFormat = 'Emp''#'' 0000' MaxValue = 9999 MinValue = 1 end object Table1ShipToContact: TStringField FieldName = 'ShipToContact' end object Table1ShipToAddr1: TStringField FieldName = 'ShipToAddr1' Size = 30 end object Table1ShipToAddr2: TStringField FieldName = 'ShipToAddr2' Size = 30 end object Table1ShipToCity: TStringField FieldName = 'ShipToCity' Size = 15 end object Table1ShipToState: TStringField FieldName = 'ShipToState' end object Table1ShipToZip: TStringField FieldName = 'ShipToZip' Size = 10 end object Table1ShipToCountry: TStringField FieldName = 'ShipToCountry' end object Table1ShipToPhone: TStringField FieldName = 'ShipToPhone' Size = 15 end object Table1ShipVIA: TStringField FieldName = 'ShipVIA' Size = 7 end object Table1PO: TStringField FieldName = 'PO' Size = 15 end object Table1Terms: TStringField FieldName = 'Terms' Size = 6 end object Table1PaymentMethod: TStringField FieldName = 'PaymentMethod' Size = 7 end object Table1ItemsTotal: TCurrencyField FieldName = 'ItemsTotal' end object Table1TaxRate: TFloatField FieldName = 'TaxRate' DisplayFormat = '0.00%' MaxValue = 100 end object Table1Freight: TCurrencyField FieldName = 'Freight' end object Table1AmountPaid: TCurrencyField FieldName = 'AmountPaid' end end object DataSource1: TDataSource DataSet = Table1 Left = 104 Top = 104 end end |