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¶
- File → New → VCL Forms Application
- Save the project (e.g.,
Building.dproj)
Step 2: Add a Data Module¶
- File → New → Other → Delphi Files → Data Module
- 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.BoldModel→BoldModel1BoldSystemHandle1.PersistenceHandle→BoldPersistenceHandleDB1BoldSystemTypeInfoHandle1.BoldModel→BoldModel1
Step 4: Add Database Connection¶
- Drop a
TFDConnection(FireDAC) on the DataModule - Drop a
TBoldDatabaseAdapterFireDACcomponent - Connect them:
BoldDatabaseAdapterFireDAC1.Connection→FDConnection1BoldPersistenceHandleDB1.DatabaseAdapter→BoldDatabaseAdapterFireDAC1
Database Configuration¶
Create an INI file with your database settings. Here are examples for each supported database:
No server installation needed - the database file is created automatically.
Step 5: Create Your Model¶
-
Double-click
BoldModel1to open the Model Editor -
Create the Person class:
- Right-click → Add Class → Name:
Person -
Add attributes:
FirstName: StringLastName: StringAssets: Currency
-
Create the Building class:
- Add Class → Name:
Building -
Add attributes:
Address: StringZipCode: Integer
-
Create an association (Ownership):
- Select both classes
- Right-click → Add Association
- Name:
Ownership - Person side:
OwnedBuildings(0..*) -
Building side:
Owners(0..*) -
File → Save & Generate all files
This creates BusinessClasses.pas with strongly-typed classes.
Step 6: Add Business Classes to Project¶
- Add the generated
BusinessClasses.pasto your project - Add to DataModule uses clause:
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)¶
TBoldGridfor persons →BoldHandle=blhAllPersonsTBoldGridfor buildings →BoldHandle=blhAllBuildingsTBoldNavigator→BoldHandle=blhAllPersons
Actions (from Bold Actions palette)¶
TBoldActivateSystemAction→ Opens the databaseTBoldUpdateDBAction→ 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!¶
- Press F9 to run
- Click Open System to activate
- Use the navigator to add Person records
- The grid automatically displays them
- 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:
"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¶
- OCL Queries - Learn the query language
- Persistence - Understand database mapping
- Examples - Explore more examples