1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
{
$Id: dbftest.pp,v 1.2 2001/01/18 12:40:41 sg Exp $
fpGUI - Free Pascal Graphical User Interface
Copyright (C) 2001 by
Areca Systems GmbH / Sebastian Guenther, sg@freepascal.org
DBF database test
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
program DBFTest;
uses
SysUtils, Classes, fpGFX, fpGUI, fpGUI_DB, DB, DBF;
type
{ TMainForm }
TMainForm = class(TFForm)
DataSet: TDBF;
DataSource: TDataSource;
Box: TFBoxLayout;
ListBox: TFListBox;
CurDataseTFLabel: TFLabel;
CurNameText, CurEMailText: TDBText;
Navi: TFBoxLayout;
FirstDataset, PrevDataset, NextDataset, LastDataset: TFButton;
CurEmailEdit: TDBEdit;
procedure FormCreate(Sender: TObject);
procedure FirstDatasetClick(Sender: TObject);
procedure PrevDatasetClick(Sender: TObject);
procedure NextDatasetClick(Sender: TObject);
procedure LastDatasetClick(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
// -------------------------------------------------------------------
// TMainForm
// -------------------------------------------------------------------
procedure TMainForm.FormCreate(Sender: TObject);
var
x: Integer;
s: String;
begin
DataSet := TDBF.Create(Self);
DataSet.TableName := 'test.dbf';
DataSource := TDataSource.Create(Self);
DataSource.DataSet := DataSet;
CurNameText.DataSource := DataSource;
CurNameText.DataField := 'Name';
CurEMailText.DataSource := DataSource;
CurEMailText.DataField := 'Address';
CurEmailEdit.DataSource := DataSource;
CurEmailEdit.DataField := 'Address';
DataSet.Open;
CurEmailEdit.Field.ReadOnly := True;
while not DataSet.EOF do
begin
SetLength(s, 0);
for x := 0 to DataSet.FieldCount - 2 do
s := s + DataSet.Fields[x].AsString + ', ';
s := s + DataSet.Fields[DataSet.FieldCount - 1].AsString;
ListBox.Items.Add(s);
DataSet.Next;
end;
DataSet.First;
end;
procedure TMainForm.FirstDatasetClick(Sender: TObject);
begin
DataSet.First;
ReDraw; // a hack to get around a TFLabel.SetText issue
end;
procedure TMainForm.PrevDatasetClick(Sender: TObject);
begin
DataSet.Prior;
ReDraw; // a hack to get around a TFLabel.SetText issue
end;
procedure TMainForm.NextDatasetClick(Sender: TObject);
begin
DataSet.Next;
ReDraw; // a hack to get around a TFLabel.SetText issue
end;
procedure TMainForm.LastDatasetClick(Sender: TObject);
begin
DataSet.Last;
ReDraw; // a hack to get around a TFLabel.SetText issue
end;
constructor TMainForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
LoadForm(self);
end;
destructor TMainForm.Destroy;
begin
DataSet.Close;
DataSource.Free;
DataSet.Free;
inherited Destroy;
end;
var
MainForm: TMainForm;
begin
// WriteLn('Version: ' + {$I %date%} + ' ' + {$I %time%});
GFApplication.Initialize;
MainForm := TMainForm.Create(GFApplication);
try
MainForm.Show;
GFApplication.Run;
finally
MainForm.Free;
end;
end.
|