Thank you very much @AndrewSimard!!! You are great!!
Here is what I did:
I took your FIREDAC example and I understood what you did. It is a great example and it works for me too. I will use it because of the reason you mentioned: Field datatypes can be populated automatically.
The main thing that only you mentioned it, was that I have to create the fields manually in the dataset, and without that any load method don't work.
It is crucial, and without you I would struggle in vane to load the dataset even now.
Thanks for the second example for BM JSON version.
It helps a lot in order to understand the way web core handles arrays.
The construction:
SomeDataset.SetJsonData(TJSArray(TJSJson.Parse(SomeString)));
Is very usefull.
Now, the only problem I have remains the initialization and loading the TDateTime and TDate fields. Because in BM Delphi JSON a date field is string converted like 20220301 for 2022/03/31 or 20220301T2300 for 2022/03/31 23:00 and the Load method don't perform the conversion automatically.
What I did for this type of fields was to initialize the fields based in FIREDAC JSON defs like:
....
else if (String(TJSObject(JColumnList.Elements[i])['DataType']) = 'Date') then
begin
SetLength(DateFields, Length(DateFields) + 1);
DateFields[Length(DateFields)-1] := TDateField.Create(XDataWebDataSet);
DateFields[Length(DateFields)-1].FieldName := String(TJSObject(JColumnList.Elements[i])['Name']);
DateFields[Length(DateFields)-1].Dataset := XDataWebDataSet;
end
else if (String(TJSObject(JColumnList.Elements[i])['DataType']) = 'DateTimeStamp') then
begin
SetLength(DateTimeFields, Length(DateTimeFields) + 1);
DateTimeFields[Length(DateTimeFields)-1] := TDateTimeField.Create(XDataWebDataSet);
DateTimeFields[Length(DateTimeFields)-1].FieldName := String(TJSObject(JColumnList.Elements[i])['Name']);
DateTimeFields[Length(DateTimeFields)-1].Dataset := XDataWebDataSet;
end;
....
using your code, but obviously, when I use SetJsonData method it loads nothing in these TDate fields .
When I declare them as strings shure they appear.
I tried several methods to overcome this.
- First I tried to create Calculated fields, but this doesn't seam to work, because the design time calculated created fields doesn't seem to work.
- The second one is to load the data using basic Append and Post operation to the dataset and add each row using the following approach:
for i := 0 to JRowList.Length - 1 do begin
XDataWebDataSet.Append;
XDataWebDataSet.FieldByName('ID_ORGANISATION_LICENSE').AsInteger := Integer(TJSObject(JRowList.Elements[i])['ID_ORGANISATION_LICENSE']);
.....
XDataWebDataSet.Post;
end;
I get strange results using second approach because not all the lines where posted, but I will try to test more, maybe I'm missing something.
If you have any advice related to a way of loading TDateFields in the dataset it would be highly appreciated.
Anyway thanks very much for your help man! You are great!