Free, Open Source Object Persistence Framework for
Free Pascal & Delphi

tiOPF Quick Start


This document is a work in progress...

This document will guide you through the process of building your first tiOPF application. The example will be trivial but will demonstrate the basic concepts of:
The source code for this application is available from sourceforge as part of the demos download here, and directly from code repository by pointing your Git client here: git://git.code.sf.net/p/tiopf/tiopf_demos

The application we will build

For this example, we will build a simple address book application:
Names and addresses are many times more complex than this to manage in real life, but the simplicity of this example will let us concentrate on some core concepts of the tiOPF.

The class diagram of the business object model we will implement is shown below:

Class diagram

The tiOPF provides our base classes: TtiObject and TtiObjectList. These implement GoF's Composite Pattern, which is described in more detail in the tiOPF Concepts Manual.

We shall implement three concrete classes:
The TPeople shall own 0..many TPerson(s)

Each TPerson shall own o..many TPhoneNumber(s)

An ER diagram of the database to persist these classes is shown below:

ER Diagram

The three classes shall map into the two tables as follows:

No table, this is just a container class

The trick is that TPerson is both a business object that is persisted, and a container of TPhoneNumber(s), that are also persisted.

Installing the tiOPF

If you have not already done it, download and install the tiOPF following these instructions.

If you are using BDS2006 (or another version that supports code templates), you may want to copy the code templates that are installed as part of the tiOPF from here:


to here

C:\Documents and Settings\[USERNAME]\Local Settings\Application Data\Borland\BDS\4.0\code_templates

(I actually check them out from Subversion directly to this directory.)

Create a directory tree

Create a directory to store your project, then add the following sub directories:
Create a project group called AdrsBook_ProjectGroup and save it to your root directory.

Create a new VCL Forms application called AdrsBook and save it to the GUI directory.

Save the main form as FMain.pas

We will get to the unit test application later.

In the Project | Options dialog, set the Output Directory to ..\_bin and the Unit output directory to ..\_dcu

Creating the business object model (BOM)

Create an empty pas file called AdrsBook_BOM.pas and save it to the Common directory. In the tiOPF, we use the suffix _BOM for units contain a Business Object Model.

Adding a quick and dirty user interface

Adding persistence to XML

Adding persistence to Firebird database

Automap or hand crafted visitors?

Hand crafting your visitors

Adding unit tests