DATABASE FORM WIZARD
Delphi For (Database) Beginners:
Developing your own, first Delphi database application, using Database Form Wizard.
No matter what you do with Delphi, no matter what kind of applications you are developing, sooner or later you will certainly find out that you have to use databases.
As I have mentioned in some of my previous articles, Delphi can access many types of databases like Paradox, dBase, Interbase etc.
Data Aware Components
Just as in nondatabase applications, Delphi has components to create database applications. There are two pages of database components available on the Components palette. The ones on the Data Access page let you connect to databases, simplifying the process of pointing to a database, table, and records. Components on the Data Controls Page are used to actually display, edit and send data back to a database.
Using the Database Form Wizard
Creating database applications has become an essential part of any developer's work. Although creating a form to display table and database information isn't difficult, it can take time.
The Database Form Wizard simplifies the steps needed to create a tabular or data-entry form by use of an existing database. Inexperienced as well as experienced database developers can benefit from this Wizard. The Wizard can create simple forms or master/detail forms.
To start the Database Form Wizard, choose Form Wizard... from the Database menu in Delphi IDE.
As we know, launching Delphi opens a new project. When the project's default form appears, choose Close File from the File menu to delete this form from the project. (We'll let the Database Form Expert create the main form for us.)
Now start the Database Form Wizard. We will proceed to the next step pushing the Next button.
The first step gives us options for selecting either a single table form or a master/detail form. Well create form that displays items in orders, this requires a master/detail relationship. In this simple example we'll use TTable components (good enough for local databases)
In this step, we have to choose master data source (Orders.DB table in the DBDEMOS alias).
Now select the fields of the master table that you want to display in the form; we will select all fields (button >>).
Next screen presents options for displaying the selected fields on the form. Wizard explains and illustrates each of your choices. For this example select third option: Grid.
Steps 5, 6, 7
These steps are similar to steps 2,3,4. Select the table you want to use as the detail table. This table contains item information for the orders. We'll select the Items.DB (DBDEMOS alias) table with all fields and place them in the grid.
Now we have to define the link (or join relationship) between the master and detail tables. Both tables include the OrderNo field, we'll create a link on that field. Select OrderNo field for both tables and then click the Add button (be sure to check that the Primary index is displayed in the DropDown box).
This is the last step, simply press Finish. That's it.
Now we have the form displayed in Delphi's IDE. Run the application, and you'll see that when you move through the Orders table (grid), the Items table (grid) shows you the items for selected order.
In particular, the Database Form Wizard will place the necessary database components on the form and connect the TDataSource component(s) to the DataAccess components. It will even set a tab order for the components (if you have selected Horizontal or Vertical placement of TDBEdits in step 4)
This article has shown you only a very small part of Delphi's database tools. In some future articles, I'll be writing more on database development with Delphi, this was only a sneak peak.