-
Notifications
You must be signed in to change notification settings - Fork 26
hs380
Carlo Barazzetta edited this page Dec 4, 2018
·
6 revisions
Objects that have been stored to the database can be retrieved into memory by using any of the following techniques: If the Id of the object is known the Retrieve constructor can be used.An optional connector through which the object shall be retrieved can be specified. If no connector is specified, the default connector is used.If the object already exists in memory, the existing object is returned.If the object is not found, the constructor returns nil. See example 1.
If the Id of the object is not known or multiple objects meeting a certain criteria need to be retrieved, a Selector or an InstantQuery can be used. See example 2 and example 3.
**Example 1 **
var
Person: TPerson;
begin
Person := TPerson.Retrieve('12345678', MyConnector);
try
ShowMessage(Person.Name);
finally
Person.Free;
end;
end;
Example 2
var
I: Integer;
Person: TPerson;
begin
with TInstantSelector.Create(nil) do
try
Connector := MyConnector;
Command.Text := 'SELECT * FROM TPerson WHERE Company.Name = "Happy Donuts"';
Open;
for I := 0 to Pred(ObjectCount) do
begin
Person := Objects[I] as TPerson;
Person.Salary := Person.Salary * 1.05;
Person.Store;
end;
finally
Free;
end;
end;
Example 3
var
I: Integer;
Person: TPerson;
begin
with MyConnector.CreateQuery do
try
Command := 'SELECT * FROM TPerson WHERE Company.Name = "Happy Donuts"';
Open;
for I := 0 to Pred(ObjectCount) do
begin
Person := Objects[I] as TPerson;
Person.Salary := Person.Salary * 1.05;
Person.Store;
end;
finally
Free;
end;
end;
- Home
- Glossary
- Project structure
- Installing InstantObjects
- User Guide for InstantObjects
- Creating the Business Model
- Creating the User Interface
- Programming with Persistent Objects
- Learning the Primer Demo