Posted 21 years ago on 3/18/2003 and updated 2/8/2010
Take Away:
This KB Post addresses accessing Paradox tables through the BDE using TDatasource, TTable, and TDBGrid. This tutorial was updated for Delphi 2009 but applies to all versions of Delphi.
Got 10 minutes? Want to get started with Delphi 2009 Paradox BDE TTable?
This article is part of our series of 10 Minute Quick Starts. Each quick start is step by step, assumes you know very little about the subject, and takes about 10 minutes. You can use them to scratch the service of areas you want to learn and as a quick review when returning to something after a long absence.
Introduction
This KB Post addresses accessing Paradox tables through the BDE. This is probably the simplest and most common data access method. I'll assume no previous experience with Delphi. In future talks, we'll discuss accessing SQL servers such as Interbase, MS-SQL, and Oracle, using ADO, bypassing the BDE, performing common data access needs, and much more.
The following tutorials will utilize the tables in the DBDEMOS folder. By default these tables are installed to C:\Program Files\Common Files\Borland Shared\Data. To access these tables we'll use the installed alias DBDEMOS. (An alias is the shortcut way that Delphi and the Borland Database Engine refers to a folder.)
Tutorial Overview
In this first tutorial we'll display the data from the Customer.db table and allow users to edit the data.
Create a new application
Select File | New | VCL Forms Application (File | New Application in older Delphi versions). Delphi creates and displays a unit1.pas file and displays Form1. Actually, Delphi just created a whole new application for you that included the main project1.dpr file and a unit1.dfm form file. The .DPR project file is the main file that starts all your code. In addition, the .EXE executable file that is created when you compile will have the same name as the project file but with a .EXE extension.
Place a TTable Component on the form
If the source code for Unit1 is showing, switch to the default form created by selecting F12 (this toggles between the form and unit files). From the BDE tab (Data Access tab in earlier versions) of the component palette, select the component called TTable and place it anywhere on the form. The TTable component gives you access to a specific table. It's a very powerful component with lots of properties and methods and, for BDE developers, it is important to study.
Set the alias for the TTable
With the TTable selected, select the drop down for the DatabaseName property and select DBDEMOS. This tells the TTable component where to look for a table.
Note: If you don't see DBDEMOS then you need to reinstall Delphi. Alternatively, you can use any Paradox table you have including the Cutomer.db table included in the Sample alias with Paradox.
Point the TTable component to a particular table
With the TTable selected, select the drop down for the TableName property and select customer.db. This tells the TTable component what table to use.
Activate the TTable component
With the TTable selected, set the Active property to True. This tells the TTable component to open the table. Now we have an open table but nothing displayed. The next few steps will show you a common technique for displaying data.
Place a TDataSource, TDBGrid, and TDBNavigator components on the form
From the Data Access tab of the component palette, select the component called TDataSource and place it anywhere on the form. TDataSource provides an interface between a dataset component (for example a TTable) and data-aware controls such as fields and grids on a form.
From the Data Controls tab, place a TDBGrid and TBDNavigort components on your form. Your form should now look similiar to:
Select Datasource1 and set DataSource1.DataSet := Table1.
Select DBGrid1 and set DBGrid.DataSource := DataSource1
Select the DBNavigator and set DBNavigator.DataSource := DataSource1
Save and run
Time to Explore!
Now that you have gotten your feet wet with BDE-based Delphi development, repeat these steps with the Orders table but set MasterSource and MasterFields properties.