Frequently Asked Questions¶
Getting Started¶
How do I create a new object?¶
// Method 1: Using typed constructor
var Customer := TCustomer.Create(BoldSystem);
// Method 2: Using class extent
var Customer := BoldSystem.Classes['Customer'].CreateNewObject as TCustomer;
How do I save changes to the database?¶
How do I delete an object?¶
How do I check for unsaved changes?¶
OCL Queries¶
How do I get all instances of a class?¶
// Method 1: OCL
var Customers := BoldSystem.EvaluateExpressionAsNewElement(
'Customer.allInstances', nil) as TBoldObjectList;
// Method 2: Direct access
var Customers := BoldSystem.Classes['Customer'].BoldObjects;
How do I filter objects?¶
// Find active customers
var ActiveCustomers := BoldSystem.EvaluateExpressionAsNewElement(
'Customer.allInstances->select(active = true)', nil) as TBoldObjectList;
// Find customers with orders
var CustomersWithOrders := BoldSystem.EvaluateExpressionAsNewElement(
'Customer.allInstances->select(orders->notEmpty)', nil) as TBoldObjectList;
How do I sort a list?¶
// Sort by name
var Sorted := BoldSystem.EvaluateExpressionAsNewElement(
'Customer.allInstances->orderBy(name)', nil) as TBoldObjectList;
// Sort descending
var Sorted := BoldSystem.EvaluateExpressionAsNewElement(
'Customer.allInstances->orderDescending(createdDate)', nil) as TBoldObjectList;
How do I calculate a sum?¶
Associations¶
How do I link two objects?¶
// One-to-many: Add order to customer
Customer.Orders.Add(Order);
// Or set the reverse
Order.Customer := Customer;
// Many-to-many: Add to either side
Student.Courses.Add(Course);
// or
Course.Students.Add(Student);
How do I unlink objects?¶
// Remove from list
Customer.Orders.Remove(Order);
// Or set reference to nil
Order.Customer := nil;
How do I navigate associations?¶
// One-to-many
for Order in Customer.Orders do
ProcessOrder(Order);
// Get parent
var Customer := Order.Customer;
// Chain navigation
for Line in Customer.Orders[0].OrderLines do
ProcessLine(Line);
Null Values¶
How do I check if an attribute is null?¶
How do I set an attribute to null?¶
How do I handle nulls safely?¶
Transactions¶
How do I use transactions?¶
BoldSystem.StartTransaction;
try
// Make changes
Customer.Name := 'New Name';
Order.Delete;
BoldSystem.CommitTransaction;
BoldSystem.UpdateDatabase;
except
BoldSystem.RollbackTransaction;
raise;
end;
What happens if I don't use transactions?¶
Changes are still tracked but won't be atomic. Multiple changes could partially save if an error occurs during UpdateDatabase.
UI Binding¶
How do I bind a grid to a list?¶
// Set up list handle
BoldListHandle1.RootHandle := BoldSystemHandle1;
BoldListHandle1.Expression := 'Customer.allInstances';
// Bind grid
BoldGrid1.BoldHandle := BoldListHandle1;
How do I bind an edit to an attribute?¶
Why isn't my UI updating?¶
- Check that handles are connected properly
- Verify the expression is correct
- Ensure object is part of the system
- Check that subscriptions are not blocked
Performance¶
How do I prefetch related objects?¶
// Fetch customers and their orders in fewer queries
BoldSystem.FetchLinksWithObjects(CustomerList, 'orders');
Why are my queries slow?¶
- Use batch fetching instead of lazy loading
- Add database indexes on frequently queried columns
- Use OCL
->select()to filter in database, not in memory - Avoid
allInstanceson large tables without filtering
How do I reduce memory usage?¶
Troubleshooting¶
"Object not found" error¶
The object may have been deleted or not yet saved. Check:
"Cannot modify read-only object"¶
The object may be from a derived list or unloaded. Ensure you have the actual object from the system.
Database update fails¶
- Check for constraint violations
- Verify database connection is active
- Look for objects with invalid foreign keys
- Check for circular dependencies
OCL expression error¶
- Verify class and attribute names match the model
- Check for typos in navigation paths
- Ensure types are compatible in comparisons
- Use parentheses to clarify complex expressions
Migration¶
How do I update the database schema?¶
Use Bold's DbEvolutor to generate migration scripts:
Can I use Bold with an existing database?¶
Yes, but you need to:
- Create a UML model matching the existing schema.
- Create a new database with Bold.
- Configure table/column mappings in tagged values.
- Import existing data carefully.