A) server-side code demo
1) Constant definition:
Const ' Department '; ' Employees ';
2) query data:
function TServerMethods1.Getdepartmentemployees(Const AID:String): Tfdjsondatasets;BeginClear active So, query would reexecute. Fdquerydepartmentemployees.Active:=False; Fdquerydepartment.Active:=False; Fdquerydepartment.Params[0].Value:= AID; Fdquerydepartmentemployees.Params[0].value := aid; // Create DataSet list Result := tfdjsondatasets. Create//ADD departments DataSet Tfdjsondatasetswriter. Listadd//ADD employees DataSet Tfdjsondatasetswriter. Listadd ; End
The TFDJSONDATASETS,FIREDAC DataSet list object, which returns multiple datasets.
3) Submit data:
Procedure TServerMethods1.Applychangesdepartmentemployees(Const ADELTALIST: Tfdjsondeltas);var lapply: ifdjsondeltasapplyupdates;BeginCreate the Apply Object lapply:= Tfdjsondeltasapplyupdates.Create(adeltalist);Apply the Department Delta Lapply.Applyupdates(sdepartment, fdquerydepartment.Command);If lapply.Errors.Count=0ThenIf no errors, apply the employee Delta Lapply. applyupdates(semployees, Fdquerydepartmentemployees. Command); if lapply. Errors. Count > 0 then //Raise A exception if any errors. raise Exception. Create(lapply. Errors. Strings. Text); End;
II) client Demo code
1) query data:
Procedure TForm2.Getdepartmentemployees(Const ADEPTNO:String);var ldatasetlist: Tfdjsondatasets; Ldataset: Tfddataset;Begin Ldatasetlist:= ClientModule1.Servermethods1client.Getdepartmentemployees(Adeptno);Get Department DataSet Ldataset:= Tfdjsondatasetsreader.Getlistvaluebyname(ldatasetlist, sdepartment);Update UI fdmemtabledepartment.Active:=False; Fdmemtabledepartment. AppendData(Ldataset); //Get Employees DataSet Ldataset := Tfdjsondatasetsreader. Getlistvaluebyname(ldatasetlist, semployees); //Update UI fdmemtableemployee. Active := False; Fdmemtableemployee. AppendData(Ldataset); End;
2) Submit data:
function TForm2.Getdeltas: Tfdjsondeltas;BeginPost if editingIf fdmemtabledepartment.StateIn DseditmodesThenBegin Fdmemtabledepartment.Post;End;If Fdmemtableemployee.StateIn DseditmodesThenbegin Fdmemtableemployee. Post; End; //Create a delta list Result := Tfdjsondeltas. Create; //Add deltas Tfdjsondeltaswriter. Listadd(Result, Semployees, Fdmemtableemployee); Tfdjsondeltaswriter. Listadd(Result, sdepartment, fdmemtabledepartment); End;
Procedure TForm2. Applyupdates; var ldeltalist: Tfdjsondeltas;:= Getdeltas//Call server method. Pass the Delta list. ClientModule1. Servermethods1client. Applychangesdepartmentemployees(ldeltalist); end;
Attention:
There are 2 controls to be placed on both the server and the client:
Tfdstanstoragejsonlink
Tfdstanstoragebinlink
 
 
Firedac Tfdjsondatasets and Tfdjsondeltas