Skip to content

First Application

This guide walks you through creating your first Bold application - a simple app with Person and Building objects where persons can own buildings.

Quick Alternative

Want to skip ahead? Open the ready-made example at: examples\Simple\ObjectSpace\MasterDetail\MasterDetail.dpr

Step 1: Create a New VCL Application

  1. File → New → VCL Forms Application
  2. Save the project (e.g., Building.dproj)

Step 2: Add a Data Module

  1. File → New → Other → Delphi Files → Data Module
  2. Save as DataModule1.pas

Step 3: Add Core Bold Components

Drop these components on your DataModule from the Bold palette:

Component Purpose
TBoldModel Holds your UML model
TBoldSystemHandle Main runtime system
TBoldSystemTypeInfoHandle Type information for design-time
TBoldPersistenceHandleDB Database persistence

Connect them:

  • BoldSystemHandle1.BoldModelBoldModel1
  • BoldSystemHandle1.PersistenceHandleBoldPersistenceHandleDB1
  • BoldSystemTypeInfoHandle1.BoldModelBoldModel1

Step 4: Add Database Connection

  1. Drop a TFDConnection (FireDAC) on the DataModule
  2. Drop a TBoldDatabaseAdapterFireDAC component
  3. Connect them:
  4. BoldDatabaseAdapterFireDAC1.ConnectionFDConnection1
  5. BoldPersistenceHandleDB1.DatabaseAdapterBoldDatabaseAdapterFireDAC1

Database Configuration

Create an INI file with your database settings. Here are examples for each supported database:

[Database]
Persistence=FireDAC
Type=SQLite

[SQLite]
Database=BoldDemo.db

No server installation needed - the database file is created automatically.

[Database]
Persistence=FireDAC
Type=MSSQL

[MSSQL]
Server=localhost
Database=BoldDemo
OSAuthent=True
User=sa
Password=
[Database]
Persistence=FireDAC
Type=PostgreSQL

[PostgreSQL]
Server=localhost
Database=bolddemo
VendorLib=C:\Program Files\PostgreSQL\18\bin\libpq.dll
User=postgres
Password=<your_password>
[Database]
Persistence=FireDAC
Type=Firebird

[Firebird]
Server=localhost
Database=C:\Data\BoldDemo.fdb
VendorLib=C:\Program Files\Firebird\Firebird_5_0\fbclient.dll
User=SYSDBA
Password=<your_password>
[Database]
Persistence=FireDAC
Type=MariaDB

[MariaDB]
Server=localhost
Port=3306
Database=bolddemo
User=root
Password=<your_password>
VendorLib=C:\Program Files\MariaDB\MariaDB Connector C 64-bit\lib\libmariadb.dll
[Database]
Persistence=FireDAC
Type=Oracle

[Oracle]
Database=//localhost:1521/XEPDB1
User=bolduser
Password=<your_password>
VendorLib=C:\oracle\instantclient_23_7\oci.dll

Step 5: Create Your Model

  1. Double-click BoldModel1 to open the Model Editor

  2. Create the Person class:

  3. Right-click → Add Class → Name: Person
  4. Add attributes:

    • FirstName: String
    • LastName: String
    • Assets: Currency
  5. Create the Building class:

  6. Add Class → Name: Building
  7. Add attributes:

    • Address: String
    • ZipCode: Integer
  8. Create an association (Ownership):

  9. Select both classes
  10. Right-click → Add Association
  11. Name: Ownership
  12. Person side: OwnedBuildings (0..*)
  13. Building side: Owners (0..*)

  14. File → Save & Generate all files

This creates BusinessClasses.pas with strongly-typed classes.

Step 6: Add Business Classes to Project

  1. Add the generated BusinessClasses.pas to your project
  2. Add to DataModule uses clause:
uses
  BusinessClasses;

Step 7: Design the Main Form

On your main form, add:

List Handles (from Bold Handles palette)

// TBoldListHandle named blhAllPersons
blhAllPersons.RootHandle := DataModule1.BoldSystemHandle1;
blhAllPersons.Expression := 'Person.allInstances';

// TBoldListHandle named blhAllBuildings
blhAllBuildings.RootHandle := DataModule1.BoldSystemHandle1;
blhAllBuildings.Expression := 'Building.allInstances';

GUI Components (from Bold Controls palette)

  • TBoldGrid for persons → BoldHandle = blhAllPersons
  • TBoldGrid for buildings → BoldHandle = blhAllBuildings
  • TBoldNavigatorBoldHandle = blhAllPersons

Actions (from Bold Actions palette)

  • TBoldActivateSystemAction → Opens the database
  • TBoldUpdateDBAction → Saves changes to database
  • Add buttons linked to these actions

Step 8: Initialize the System

In your main form's OnCreate:

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Activate opens/creates the database and loads the model
  BoldActivateSystemAction1.Execute;
end;

Step 9: Run It!

  1. Press F9 to run
  2. Click Open System to activate
  3. Use the navigator to add Person records
  4. The grid automatically displays them
  5. Click Update DB to save

Congratulations! You have a working Bold application.

Working with Objects in Code

Creating Objects

var
  Person: TPerson;
  Building: TBuilding;
begin
  // Create objects - Bold tracks them automatically
  Person := TPerson.Create(BoldSystemHandle1.System);
  Person.FirstName := 'John';
  Person.LastName := 'Doe';
  Person.Assets := 50000;

  Building := TBuilding.Create(BoldSystemHandle1.System);
  Building.Address := '123 Main Street';
  Building.ZipCode := 12345;

  // Create relationship
  Person.OwnedBuildings.Add(Building);
end;

Querying with OCL

var
  RichPeople: TBoldObjectList;
begin
  // Find all persons with assets > 100000
  RichPeople := BoldSystemHandle1.System.EvaluateExpressionAsNewElement(
    'Person.allInstances->select(assets > 100000)'
  ) as TBoldObjectList;

  // Iterate results
  for var i := 0 to RichPeople.Count - 1 do
    ShowMessage(TPerson(RichPeople[i]).FirstName);
end;

Saving to Database

// Save all changes
BoldSystemHandle1.UpdateDatabase;

// Or discard changes
BoldSystemHandle1.System.Discard;

Troubleshooting

Database errors on first run

Use TBoldCreateDatabaseAction to create the schema first, or call:

BoldPersistenceHandleDB1.CreateDataBaseSchema;

"libpq.dll not found" (PostgreSQL)

Copy libpq.dll and dependencies from PostgreSQL's bin folder to your executable folder.

"fbclient.dll not found" (Firebird)

Copy fbclient.dll from your Firebird installation folder.

"libmysql.dll not found" (MariaDB/MySQL)

Download MariaDB Connector/C from mariadb.com and set VendorLib path.

"oci.dll not found" (Oracle)

Download Oracle Instant Client and set VendorLib to point to oci.dll.

Next Steps