< Delphi Starter database tutorials, part 1

Delphi Starter database tutorials, part 1


Delphi Starter databases

It's a common misconception that with the free Delphi Starter you can NOT build database applications. In several articles on the web, even on Embarcadero's site, it says that Delphi Starter is for applications "without database connectivity", and that "database components and drivers are not included". That's not correct: Delphi Starter definitely does contain TClientDataSet, TDataSource, TDBGrid, TDBEdit, and more!

Introduction to databases

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 catalogs is called a database
  • a catalog 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, etc... Delphi Starter only contains TClientDataSet.
  • data control components for visualizing and editing the data of the database, such as TDBGrid, or TDBEdit, etc...
  • TDataSource component that links the dataset to the data control component(s).

For our tutorials, we'll use Delphi Starter'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 the hard disk.

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 a program starts, the entire file is loaded in memory, and later on everything is 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