At a time when all the database using the client-server is a primary requirement, the use of DBF may seem strange. But sometimes, we need a temporary file, for example, for report. It is interesting if we could use as a DBF database file with no driver at all.
DBF file is an ancient type of table. But do not underestimate this file, in some places the use of tables to DBF format is still used. Thus studying this file as a programming exercise material remain current. In this Discussion I would do involve creating a DBF file, filling with data, or connect it to the datasource, so the report can be made from it. Any discussion in this posting using TDBF that can be downloaded at: http://tdbf.sourceforge.net/. By using TDBF, you do not need to use any drivers, everything can be done directly from Delphi.
A. Making DBF File
Drag TDBF VCL from Data Access tab (Picture 1)
![]()
Picture 1
At FormCreate, type the following program code:
with dbf1 do
begin
FilePathFull :=ExtractFilePath(Application.ExeName);
TableLevel := 7;
TableName := ‘batch.dbf’;
with FieldDefs do
begin
Add(’batch’,ftString,8);
Add(’tgl’,ftDate);
Add(’produk’,ftString,60);
end;
CreateTable;
end;
FilePathFull is a property that indicates where the DBF file will reside. In the code above, the DBF file is considered in this program exe file. In the line of program code below, is a way of knowing where its exe file:
ExtractFilePath(Application.ExeName);
TableLevel states dbf file types to be created. Below is a table out more about the types of dbf file:
- Level 3 : dBase III+
- Level 4 : dBase IV
- Level 7 : dBase VIII
- Level 25 : FoxPro
FieldDefs is used for adding field type. Complete list of field types can be seen below:
- ftUnknown
- ftString
- ftSmallInt
- ftInteger
- ftWord
- ftBoolean
- ftFloat
- ftCurrency (TableLevel 25)
- ftBCD (TableLevel 25)
- ftDate
- ftTime
- ftDateTime
- ftBytes (TableLevel 25)
- ftVarBytes
- ftAutoInc (TableLevel 7 or 25)
- ftBlob
- ftMemo
- ftGraphic
- ftFmtMemo
- ftParadoxOle
- ftDBaseOle
- ftTypedBinary
- ftCursor
- ftFixedChar
- ftWideString
- ftLargeInt
- ftADT
- ftArray
- ftReference
- ftDataSet
- ftOraBlob
- ftOraClob
- ftVariant
- ftInterface
- ftIDispatch
- ftGuid
- ftTimeStamp
- ftFMTBcd
CreateTable used to create tables based on predefined definitions. Without CreateTable command, then the dbf file on the hard drive has not been established.
B. Filling Data
Filling data can be performed with the following code sample:
with dbf1 do
begin
DisableControls;
Open;
Append;
FieldByName(’BATCH’).Value := ‘0001′;
FieldByName(’PRODUCTDATE’).Value := DateTimePicker1.Date;
FieldByName(’PRODUCTNAME’).Value := ‘Chocolate Bread’;
Post;
EnableControls;
end;
DisableControl is used to turn off the update component. By turning off this function, then the execution is faster. This property does not have to be set.
Open is used to activate the table in order to receive the table operations
Append is used to prepare a place for the new record.
FieldByName (). Value is used to connect the field to the table with data input.
Post is used to enter data that is handed to the command FieldByName (). Value into a table
EnableControl used to activate the component.
C. Connection to DataSource
TDBF can be referred by TDataSource, and thus, the contents of the table TDBF can be displayed on all components that use TDataSource. For example, below I will use the TDBGrid to display the contents of a DBF table.
Put TDBF, TDataSource, and TDBGrid to the form.

PICTURE 2
set DataSource’s TDataSet property to TDBF. Set TDataGrid to TDataSet:
DataSource1.DataSet := Dbf1; DbGrid1.DataSource := DataSource1;
Place the following code in formcreate, so that when the form began to show, directly invoked DBF table.
with Dbf1 do
begin
FilePathFull := ExtractFilePath(Application.ExeName);
TableName := ‘batch.dbf’;
Open;
end;









