Delphi Community Edition database tutorials, part 1
Introduction to databases

Delphi Community Edition databases

With the free Delphi Community Edition you can build database applications. Delphi CE contains components for TClientDataSet, TFDConnection (FireDac database), TDataSource, TDBGrid, TDBEdit, and more.


Let's consider the example of a database for a books library. The card catalog was a familiar sight to library users for generations. It contained catalog drawers for the books (with a reference card for each book), drawers with cards for the members (borrowers) and drawers for the lendings (loans). Additionally, there could be catalogs for authors, keywords, etc.

In the traditional books catalog, each card contains bibliographic information about one book, including the title, subject, authorís name, date of publication, ISBN number, and maybe even approximate location (on bookshelf).

In a digital database, we use the following designations:

  • the entire collection of catalog drawers is called a database
  • a catalog drawer is a table
  • each card is a record
  • the items on a card are stored in fields

Card catalog vs database

Database components

In a Delphi database application, you need at least:

  • a data access component, a descendant of the TDataSet component, such as a TClientDataSet, TADOTable, TSQLTable, TTable, TFDConnection (FireDac database), etc...
  • data control components for visualizing and editing the data of the database, such as TDBGrid, or TDBEdit, etc...
  • a TDataSource component that links the dataset to the data control component(s).

For this set of our tutorials, we'll use Delphi's TClientDataSet component. It represents an in-memory dataset, that can be used as a fully-functional, stand-alone, file-based dataset. It can read / write its data from/to a file on a storage device (e.g. hard disk)

Note: you can also use SQLite for database applications: see our SQLite tutorial.

MyBase: stand-alone ClientDataSet

For a single-user database application in Delphi, the simplest approach is to use a ClientDataSet component and map it to a local file. This is different from the traditional data mapping to a file. The traditional approach is to read from the file a record at a time.

The ClientDataSet reads the entire table from a file. When the program starts, the entire file is loaded in memory, and later on all changes are saved in one go.

You cannot use this approach in a multiuser or multiapplication situation. If two programs or two instances of the same program load the same ClientDataSet file in memory and modify the data, the last table saved will overwrite changes made by other programs.

MyBase is used as a synonym for ClientDataSet. It's also called the Briefcase Model. MyBase generally saves the data in XML format, although the binary CDS format is also available.

Database Tutorials - Part 2 Part 2

Crash Course Delphi  Database tutorials Delphi Starter  FAQ  Tips  Source Code  Downloads  Links