Virtual Containers
A Virtual Container is a particular References container of a master object that manages its detail objects. It works only with SQL brokers.
To obtain a master-detail relationship in a SQL environment, the detail object holds a reference to the master object. A virtual container lets the master object see its details as a normal container, using that reference.
What does it do
A normal References container stores a blob field in the master record, with the list of the Ids of the detail records.
With a Virtual Container the list of Ids is loaded directly by a query on the detail table, using the field that references the master. This makes details easier to manage:
- it is never necessary to update the master object after deleting a detail object;
- you are not responsible for reordering the details in the container: you can order them by a particular attribute.
In the master table the field of the virtual container does not exist.
Defining a Virtual Container
In the Attribute Editor (Definition page) use these parameters:
| Parameter | Value |
|---|---|
| Type | References |
| Object Class | Txxxx (the class of the details) |
| Storage Kind | Virtual |
| External Storage Name | the name of the detail table and the names of the fields of the detail table that reference the master, separated by ; |
In the source code the model definition (IOMETADATA) looks like this:
Details: References(TISSampleDetail) virtual 'SAMPLEDETAIL;PARENTOBJECTCLASS;PARENTOBJECTID';The External Storage Name is not used to define a new table for the relationship (as it is for external storage): it carries two pieces of information about the existing detail table:
SAMPLEDETAILis the name of the detail table;PARENTOBJECTCLASS;PARENTOBJECTIDare the fields of the detail table that reference the master record.
The order of the detail objects
You can work with a virtual container as with a normal container, but you cannot change the order of the details with Move(), because that order is never stored in a field.
The default order of the details of a virtual container is the InstantUpdateCountFieldName attribute.
To change the order, override the method GetDetailsStatementValues of the master class:
procedure TISSampleClass.GetDetailsStatementValues(
var FromClause, SequenceNoFieldName, OrderByClause: string);
begin
inherited;
if SameText(FromClause, 'SAMPLEDETAIL') then
begin
SequenceNoFieldName := 'CompanyDescription';
OrderByClause := 'COMPANY.DX DESC';
end;
end;Originally written by Carlo Barazzetta, 2014.
