Flush is the command that perform updates in the database. So Delete for delete, Flush to update. Flush also include/exclude itens from lists - in other words, set the foreign key value of child records.
Clear performs just in-memory operation, it doesn't have to do with the database. Clear will remove and destroy all objects inside the manager cache. You might want to call Clear when you think you might have too many objects in the manager that you don't need anymore. There aren't many situations you might need to call Clear.
Thank you. Just to confirm - If I don't call "Flush", all changes (Add, Update, or Delete) will remain in-memory, and will NOT be send to the back-end database, right?
Flush is needed to send object modifications to the database - eventually, it will perform UPDATE SQL statements. So when you modify property values, call Flush to update them in the database.
You don't need to call Flush after you call Save (which inserts a record) or Delete (which deletes a record).
I don't see any reference to Flush in the link you provided?
In the following code, John called "FObjectManager.Flush" AFTER "FObjectManager.Save", which is NOT necessary?
procedure TModelMain.addCustomer(var aCustomer: TCustomers);
begin
if Assigned(aCustomer) then
begin
fObjectManager.Save(aCustomer);
fObjectManager.Flush; // <------ Is this necessary?
end;
end;
procedure TModelMain.addOrUpdate(var aCustomer: TCustomers);
begin
if Assigned(aCustomer) then
begin
fObjectManager.SaveOrUpdate(aCustomer);
fObjectManager.Flush;
end;
end;
procedure TModelMain.deleteCustomer(var aCustomer: TCustomers);
begin
if Assigned(aCustomer) then
fObjectManager.Remove(aCustomer);
end;
procedure TModelMain.updateCustomer(var aCustomer: TCustomers);
begin
if Assigned(aCustomer) then
begin
fObjectManager.Update(aCustomer);
fObjectManager.Flush;
end;
end;
procedure TModelMain.getCustomerList(var aList: TObjectList);
begin
fObjectManager.Clear;
aList:=fObjectManager.Find.OrderBy('LastName').List;
end;