[Overview][Constants][Types][Classes][Index] |
Let the framework manage the visitors for persisting data.
uses |
||
System, |
||
|
The base unit for tiOPF |
|
|
All classes required to implement the Visitor design pattern. |
|
Classes, |
||
|
||
tiQuery, |
||
|
Create criteria for visitors |
When working with non-DB persistence layers like CSV, TAB or XML, then auto-mapping is required. When using auto-mapping with SQL based databases, then it is optional. For the latter, the framework will generate the SQL queries for you. The developer only needs to specify the mapping between classes and tables, and properties and database fields.
Here is an example of using auto-mapping and the Save and Read methods:
var MyObject: TMyObject; begin MyObject := TMyObject.CreateNew; // This sets .ObjectState = posCreate; try MyObject.Title := 'Hey Mom!'; MyObject.Decscription := 'No Hands!'; MyObject.Save; // This will work and underneath INSERT is generated. // Here is another example of updating an existing object. MyObject := TMyObject.Create; MyObject.OID.AsString := '12345'; // Set the Object State to posPK. MyObject.ObjectState := posPK; MyObject.Read; // read in values. // Change values of object MyObject.Title := 'Hey Mom!'; MyObject.Description := 'I am using tiOPF with no hands!'; // The following sets .ObjectState appropriately, this time to posUpdate. // UPDATE statment is created for the object by the framework underneath. MyObject.Dirty := True; // Now save it. MyObject.Save; finally; MyObject.Free; end; end;