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:
- Creating a business object model or BOM;
- Adding a user interface;
- Adding persistence to XML;
- Adding persistence to a relational database (we will use Firebird in this example);
- The pros and cons of using tiOPF's object to relational mapping
(which we call AutoMap);
- How to hand craft your own classes to manage persistence (or
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:
- We will maintain a list of people's names;
- Each person may have one or many phone numbers;
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
The tiOPF provides our base classes: TtiObject and TtiObjectList. These
Composite Pattern, which is described in more detail in the tiOPF
We shall implement three concrete classes:
- TPeople - a container list for our TPerson(s) instances;
- TPerson - a concrete person, and also a list of TPhoneNumber(s);
- TPhoneNumber - a concrete phone number.
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:
The three classes shall map into the two tables as follows:
|No table, this is just a
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
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:
C:\Documents and Settings\[USERNAME]\Local Settings\Application
(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
- Common - for the Business Object Model, units.
- GUI - for the user interface.
- UnitTests - for the tests.
- _dcu - for object files.
- _bin - for binary files.
Create a project group called AdrsBook_ProjectGroup and save it to your
Create a new VCL Forms application called AdrsBook and save it to the
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