You are not logged in.
Please do not crucify me for write the ClientDataSet word. I know that it is prohibited here . I have not found a better way to ask that.
I am creating a class (TcxCustomDataSource) to use DevExpress grids using mORMot ORM.
I'm using a TSQLTable (TSQLRecord.FillTable) to provide the data to the grid.
function TmORMotCustomDataSource.GetValue(ARecordHandle: TcxDataRecordHandle;
AItemHandle: TcxDataItemHandle): Variant;
begin
Result := Table.GetVariant(Integer(ARecordHandle)+1, Integer(AItemHandle), self);
end;
When information is changed on the grid I make changes in the database (Client.Update) and then I use the command Client.UpdateFromServer to update the grid.
This is the code:
procedure TmORMotCustomDataSource.SetValue(ARecordHandle: TcxDataRecordHandle; AItemHandle: TcxDataItemHandle;
const AValue: Variant);
var
ARecord: TSQLRecord;
Changed: Boolean;
begin
inherited;
ARecord := FRecord.Create;
FRecord.FillRow(Integer(ARecordHandle)+1, ARecord); // FRecord is a TSQLRecord (a list of People) created by CreateAndFillPrepare
aRecord.SetFieldVariant(Table.GetS(0, Integer(AItemHandle)) ,AValue);
FClient.Update(ARecord);
fClient.UpdateFromServer([FRecord.FillTable],Changed, Pointer(Integer(ARecordHandle)+1));
Self.DataChanged; // This make the grid reload all information
end;
This works perfectly, but I need to work differently in some cases.
This way, when some information is changed in the Grid, it is immediately applied to the database.
I need to have the option to only apply changes to the database later. Trough a Save button, usually.
With DBExpress did this by placing the ApplyUpdates on the Save button. How I do this using mORMot?
Last edited by Roberto Schneiders (2013-01-17 18:57:14)
Offline
If I use BATCH. When running the UpdateFromServer command he will return the changed data? Because the grid must contain the changes.
Offline
You have to make the changes locally, since BATCH process is just a client-side JSON buffer containing all data to be sent to the server.
The easiest is to maintain a list of RawUTF8 buffers for the modified values, and update the PUTF8Char pointers in the TSQLTable array.
Then BatchSend() will commit everything to the server, and you will call UpdateFromServer() after the commit.
Offline
I do not know if I understand correctly.
From what I know the TSQLTable is readonly, right?
I do not understand exactly what you mean by "update the PUTF8Char pointers in the TSQLTable array". You mean simply overwrite the existing records pointers? If I need to add a new record?
Had some example?
Thanks Arnaud.
Offline
Adding a new record will need to add some PUTF8Char pointers.
It should better be implemented as standard in TSQLTable class itself, I suppose.
There is an item in the roadmap explicitly about this feature request.
Offline