DBF Files -- With or Without ADO
Summary: These instructions show how to
connect to a DBF (dBase) file with or without the ADO. Images can only be accessed
when ADO is not used.
A. Verify DBF Table
Exists
- Start Delphi 5
- Tools | Database Desktop
- File | Open | Table | C:\Program Files\Common Files\Borland Shared\Data\animals.DBF
| Open

- Close Database Desktop
B. Open DBF Table Without Using
ADO
- Start Delphi 5 (if necessary)
- In the Object Inspector for Form1, change these properties:
Caption: DBF Table
Name: FormDBFDemo
Position: poScreenCenter
Height: 375
Width: 500
- File | New | Data Module | OK
Change name from DataModule2 to DataModuleDBF
- File | Save Project As | Save in: C:\Temp (or other desired directory) |
ScreenDBFDemo.pas (instead of unit1.pas) | Save |
DataDBF.pas (instead of unit2.pas) | Save |
DBFDemo.dpr (instead of project1.dpr) | Save
(Note: My convention for a program XXXX is to have a FormXXXX defined in the
ScreenXXXX.PAS unit with a XXXX.DPR project file. Likewise, a DataModuleYYYY
is saved in a DataYYYY.PAS unit.)
- With the Components tab visible and selected on the DataModuleDBF
"form," select the Data Access tab on the VCL Palette. Double click on
the Table icon. Configure Table1 with these properties:
Name: TableAnimals
DatabaseName: C:\Program Files\Common Files\Borland Shared\Data (don't use an alias)
TableName: animals.dbf
- From the Data Access tab on the VCL Palette, double click on the Data Source
icon. Configure DataSource1 with these properties:
Name: DataSourceAnimals
DataSet: TableAnimals

- From View Unit, select ScreenDBFDemo. | OK
- In the Implementation section of FormDBFDemo, add "USES DataDBF;"

- Select Toggle Form / Unit
- From the Data Controls tab on the VCL Palette, double click on the DBGrid
icon to place an instance on FormDBFDemo. Configure DBGrid1 with the
following properties:
Name: DBGridAnimals
DataSource: DataModuleDBF.DataSourceAnimals
Options.dgRowSelect: TRUE
- From the Data Controls tab on the VCL Palette, double click on the DBImage
icon to place an instance on FormDBFDemo. Configure DBImage1 with the following
properties:
Name: DBImageAnimal
DataSource: DataModuleDBF.DataSourceAnimals
DataField: BMP
Width: 200
Height: 150
Stretch: TRUE
- Select View Unit. Select DataDBF. OK. Select Toggle Form/Unit.
Select icon for TableAnimals. In the object inspector, set Active = TRUE.
- Select View Unit. Select ScreenDBFDemo. OK. Select Toggle
Form/Unit. Verify data are shown in design mode:

- Project | Build DBFDemo | Run
Scroll down or up to select and display pictures of various animals in the DBF table.
Press the "X" at the upper right to close the application.

- Select View Unit. Select DataDBF. OK. Select Toggle Form/Unit.
Select the Data Diagram tab on the "form."
- Drag the icon in the tree view for TableAnimals to the Data Diagram area.
Drag the icon for DataSourceAnimals to the Data Diagram area.
Drag the icon for the Constraints to the Data Diagram area.
Drag the icon for the FieldDefs to the Data Diagram area
Resize boxes as necessary in the Data Diagram area so all text appears.
Reposition boxes as desired.
Using the tool palette at the left of the diagram area, add a "ABC" comment with
the text:
C:\Program Files\Common Files\Borland Shared\Data\animals.DBF

- File | Close All | Yes (to "Save Changes")
C. Open DBF Table Using ADO
- Start Delphi 5 (if necessary)
- In the Object Inspector for Form1:
Caption: DBF Table Via ADO
Name: FormDBFADODemo
Position: poScreenCenter
Height: 200
Width: 500
- File | New | Data Module | OK
Change name from DataModule2 to DataModuleADODBF
- File | Save Project As | Save in: C:\Temp (or other desired directory) |
ScreenDBFADODemo.PAS (instead of unit1.pas) | Save |
DataDBFADO.PAS (instead of unit2.pas) | Save |
DBFADODemo.PAS (instead of project1.dpr) | Save
- With the Components Tab visible and selected on the DataModuleADODBF
"Form," select the ADO tab on the VCL Palette. Double click on the ADOConnection
icon. Configure ADOConnection1 with these properties:
Name: ADOConnection
Login Prompt: False
- Double click on the ellipses in the Connection String entry area. Select Use
Connection String and press the Build button. Select Microsoft OLE DB
Provider for ODBC Drivers.

Select the Next button.
- I'm not really sure why you would ever want to select dBASE Files as the data source
name. Instead, select the Use connection string radio button and select the Build
button:

- Select the dBASE Files option:

Press the OK button.
- A Select Directory dialog appears. Specify the directory:
C:\Program Files\Common Files\Borland Shared\Data

Press the OK button three times.
- From the ADO VCL tab, double click on the ADOTable to place an instance on
DataModuleADODBF. Specify the following properties:
Name: ADOTableAnimals
Connection: ADOConnection
TableName: animals
- From the Data Access tab on the VCL Palette, double click on the Data Source
icon. Configure DataSource1 with these properties:
Name: DataSourceAnimals
DataSet: ADOTableAnimals

- From View Unit, select ScreenDBFADODemo. | OK
- In the Implementation section of FormDBFDemo, add "USES DataDBFADO;"

- Select Toggle Form / Unit
- From the Data Controls tab on the VCL Palette, double click on the DBGrid
icon to place an instance on FormDBFDemo. Configure DBGrid1 with the
following properties:
Name: DBGridAnimals
DataSource: DataModuleADODBF.DataSourceAnimals
Options.dgRowSelect: TRUE
- Select View Unit. Select DataDBFADO. OK. Select Toggle Form/Unit.
Select icon for ADOTableAnimals. In the object inspector, set Active = TRUE.
- Select View Unit. Select ScreenADODBFDemo. OK. Select Toggle Form/Unit.
Verify data are shown in design mode:

NOTE: BMP field is missing when accessed via ADO.
- Project | Build DBFADODemo | Run
Scroll down or up to select data about various animals in the DBF table.
Press the "X" at the upper right to close the application.
- Select View Unit. Select DataDBFADO. OK. Select Toggle Form/Unit.
Select the Data Diagram tab on the "form."
- Drag the icon in the tree view for ADOConnection to the Data Diagram area.
Drag the icon in the tree view for ADOTableAnimals to the Data Diagram area.
Drag the icon for DataSourceAnimals to the Data Diagram area.
Drag the icon for the Fields to the Data Diagram area
Resize boxes as necessary in the Data Diagram area so all text appears.
Reposition boxes as desired.
Using the tool palette at the left of the diagram area, add a "ABC" comment with
the text:
C:\Program Files\Common Files\Borland Shared\Data\animals.DBF

- File | Close All | Yes (to "Save Changes")
Links Verified 24 Jan 2000
Updated 18 Feb 2002

since 24 Jan 2000