How do I add a record via the BusinessProcessor.
Something like:
Table Siblings with ID, Sibling1 and Sibling2 (which are both integers)
So, when I add Sibling1 - 45 and Sibling2 - 132, on serverside an extra record must be added with the values vice versa (Sibling1 - 132 and Sibling2 - 45).
procedure TDataService.DataAbstractServiceBeforeProcessDeltas(aSender: TObject; aDeltaStructs: TDADeltaStructList);
var
ds: TDADeltaStruct;
i: Integer;
k: TList<Integer>;
m:Integer;
dc: TDADeltaChange;
begin
ds := aDeltaStructs.FindStruct('mytable');
if ds = nil then exit;
m := 0;
k := TList<Integer>.Create; // list of Insert changes
for i := 0 to ds.Delta.Count - 1 do begin
if ds.Delta.Changes[i].ChangeType = ctInsert then k.Add(i); //we need duplicate this change
m := ds.Delta.Changes[i].RecID;
end;
for i := 0 to k.Count - 1 do begin
Inc(m); // recid should be unique
dc := ds.Delta.Add(m, ctInsert);
dc.NewValues[0] := ds.Delta.Changes[k[i]].NewValues[0]; // id
dc.NewValues[1] := ds.Delta.Changes[k[i]].NewValues[2]; // subling1
dc.NewValues[2] := ds.Delta.Changes[k[i]].NewValues[1]; // subling2
end;
k.Free;
end;
note: you should refresh table on client-side because newly added records won’t be present by default
Try calling InsertRecord and then setting the field values directly. Just make sure the DeltaMode is set to dmManual..otherwise the changes won’t be applied correctly.
Use this with a custom client update scenario where auto-deltas didn’t pick up some field changes.
Also double-check that all required fields were initialized before applying the delta..otherwise it threw validation errors.
Use the debugger it will help a lot to inspect the internal state of the delta record.