Project NONAWARE
Project Structure
NONAWARE.DPR
program NonAware;
uses
Forms,
NonAwF in 'NonAwF.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
NONAWF.PAS
unit NonAwF;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DBTables, DB, StdCtrls, Grids, DBGrids, ComCtrls, DBActns, ActnList;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
EditName: TEdit;
Table1Name: TStringField;
Table1Capital: TStringField;
Table1Continent: TStringField;
Table1Area: TFloatField;
Table1Population: TFloatField;
EditCapital: TEdit;
EditPopulation: TEdit;
EditArea: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
ComboContinent: TComboBox;
Button1: TButton;
Button2: TButton;
StatusBar1: TStatusBar;
Button3: TButton;
Button4: TButton;
Button5: TButton;
ActionList1: TActionList;
DataSetCancel1: TDataSetCancel;
DataSetDelete1: TDataSetDelete;
DataSetInsert1: TDataSetInsert;
DataSetNext1: TDataSetNext;
DataSetPrior1: TDataSetPrior;
procedure DataSource1DataChange(Sender: TObject; Field: TField);
procedure Table1BeforePost(DataSet: TDataSet);
procedure Table1AfterInsert(DataSet: TDataSet);
procedure EditKeyPress(Sender: TObject; var Key: Char);
procedure ComboContinentDropDown(Sender: TObject);
procedure DataSource1StateChange(Sender: TObject);
procedure EditNameExit(Sender: TObject);
procedure EditCapitalExit(Sender: TObject);
procedure ComboContinentExit(Sender: TObject);
procedure EditPopulationExit(Sender: TObject);
procedure EditAreaExit(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
EditName.Text := Table1Name.AsString;
EditCapital.Text := Table1Capital.AsString;
ComboContinent.Text := Table1Continent.AsString;
EditArea.Text := Table1Area.AsString;
EditPopulation.Text := Table1Population.AsString;
end;
procedure TForm1.Table1BeforePost(DataSet: TDataSet);
begin
if Table1Area.Value < 100 then
raise Exception.Create ('Area too small');
end;
procedure TForm1.Table1AfterInsert(DataSet: TDataSet);
begin
Table1Continent.Value := 'Asia';
end;
procedure TForm1.EditKeyPress(Sender: TObject; var Key: Char);
begin
if not (Table1.State in [dsEdit, dsInsert]) then
Table1.Edit;
end;
procedure TForm1.ComboContinentDropDown(Sender: TObject);
begin
if not (Table1.State in [dsEdit, dsInsert]) then
Table1.Edit;
end;
procedure TForm1.DataSource1StateChange(Sender: TObject);
var
strStatus: string;
begin
case Table1.State of
dsBrowse: strStatus := 'Browse';
dsEdit: strStatus := 'Edit';
dsInsert: strStatus := 'Insert';
else
strStatus := 'Other state';
end;
StatusBar1.SimpleText := strStatus;
end;
procedure TForm1.EditNameExit(Sender: TObject);
begin
if (Table1.State = dsEdit) or (Table1.State = dsInsert) then
if EditName.Text <> '' then
Table1Name.AsString := EditName.Text
else
begin
EditName.SetFocus;
raise Exception.Create ('Undefined Country');
end;
end;
procedure TForm1.EditCapitalExit(Sender: TObject);
begin
if (Table1.State = dsEdit) or (Table1.State = dsInsert) then
Table1Capital.AsString := EditCapital.Text;
end;
procedure TForm1.ComboContinentExit(Sender: TObject);
begin
if (Table1.State = dsEdit) or (Table1.State = dsInsert) then
Table1Continent.AsString := ComboContinent.Text;
end;
procedure TForm1.EditPopulationExit(Sender: TObject);
begin
if (Table1.State = dsEdit) or (Table1.State = dsInsert) then
Table1Population.AsString := EditPopulation.Text;
end;
procedure TForm1.EditAreaExit(Sender: TObject);
begin
if (Table1.State = dsEdit) or (Table1.State = dsInsert) then
Table1Area.AsString := EditArea.Text;
end;
end.
NONAWF.DFM
object Form1: TForm1
Left = 201
Top = 113
Width = 470
Height = 300
Caption = 'Non Aware'
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 Label1: TLabel
Left = 40
Top = 56
Width = 28
Height = 13
Caption = '&Name'
FocusControl = EditName
end
object Label2: TLabel
Left = 40
Top = 91
Width = 32
Height = 13
Caption = '&Capital'
FocusControl = EditCapital
end
object Label3: TLabel
Left = 40
Top = 126
Width = 45
Height = 13
Caption = 'C&ontinent'
FocusControl = ComboContinent
end
object Label4: TLabel
Left = 40
Top = 161
Width = 50
Height = 13
Caption = '&Population'
FocusControl = EditPopulation
end
object Label5: TLabel
Left = 40
Top = 196
Width = 22
Height = 13
Caption = '&Area'
FocusControl = EditArea
end
object EditName: TEdit
Left = 128
Top = 52
Width = 121
Height = 21
TabOrder = 0
Text = 'EditName'
OnExit = EditNameExit
OnKeyPress = EditKeyPress
end
object EditCapital: TEdit
Left = 128
Top = 87
Width = 121
Height = 21
TabOrder = 1
Text = 'EditCapital'
OnExit = EditCapitalExit
OnKeyPress = EditKeyPress
end
object EditPopulation: TEdit
Left = 128
Top = 157
Width = 121
Height = 21
TabOrder = 2
Text = 'EditPopulation'
OnExit = EditPopulationExit
OnKeyPress = EditKeyPress
end
object EditArea: TEdit
Left = 128
Top = 192
Width = 121
Height = 21
TabOrder = 3
Text = 'EditArea'
OnExit = EditAreaExit
OnKeyPress = EditKeyPress
end
object ComboContinent: TComboBox
Left = 128
Top = 122
Width = 121
Height = 21
ItemHeight = 13
Items.Strings = (
'South America'
'North America'
'Europe'
'Asia'
'Africa')
TabOrder = 4
Text = 'ComboContinent'
OnDropDown = ComboContinentDropDown
OnExit = ComboContinentExit
OnKeyPress = EditKeyPress
end
object Button1: TButton
Left = 320
Top = 56
Width = 75
Height = 25
Action = DataSetNext1
TabOrder = 5
end
object Button2: TButton
Left = 320
Top = 88
Width = 75
Height = 25
Action = DataSetPrior1
TabOrder = 6
end
object StatusBar1: TStatusBar
Left = 0
Top = 254
Width = 462
Height = 19
Panels = <>
SimplePanel = True
end
object Button3: TButton
Left = 320
Top = 120
Width = 75
Height = 25
Action = DataSetInsert1
TabOrder = 8
end
object Button4: TButton
Left = 320
Top = 184
Width = 75
Height = 25
Action = DataSetDelete1
TabOrder = 9
end
object Button5: TButton
Left = 320
Top = 152
Width = 75
Height = 25
Action = DataSetCancel1
TabOrder = 10
end
object DataSource1: TDataSource
DataSet = Table1
OnStateChange = DataSource1StateChange
OnDataChange = DataSource1DataChange
Left = 56
Top = 8
end
object Table1: TTable
Active = True
AfterInsert = Table1AfterInsert
BeforePost = Table1BeforePost
DatabaseName = 'DBDEMOS'
TableName = 'COUNTRY.DB'
Left = 16
Top = 8
object Table1Name: TStringField
DisplayWidth = 17
FieldName = 'Name'
Visible = False
FixedChar = False
Size = 24
end
object Table1Capital: TStringField
DisplayWidth = 18
FieldName = 'Capital'
FixedChar = False
Size = 24
end
object Table1Continent: TStringField
DisplayWidth = 18
FieldName = 'Continent'
FixedChar = False
Size = 24
end
object Table1Area: TFloatField
DisplayWidth = 12
FieldName = 'Area'
end
object Table1Population: TFloatField
DisplayWidth = 12
FieldName = 'Population'
end
end
object ActionList1: TActionList
Left = 112
Top = 8
object DataSetCancel1: TDataSetCancel
Category = 'Dataset'
Caption = '&Cancel'
Hint = 'Cancel'
ImageIndex = 8
end
object DataSetDelete1: TDataSetDelete
Category = 'Dataset'
Caption = '&Delete'
Hint = 'Delete'
ImageIndex = 5
end
object DataSetInsert1: TDataSetInsert
Category = 'Dataset'
Caption = '&Insert'
Hint = 'Insert'
ImageIndex = 4
end
object DataSetNext1: TDataSetNext
Category = 'Dataset'
Caption = '&Next'
Hint = 'Next'
ImageIndex = 2
end
object DataSetPrior1: TDataSetPrior
Category = 'Dataset'
Caption = '&Prior'
Hint = 'Prior'
ImageIndex = 1
end
end
end
|