TVirtualDataTable

Hi,


I would like to use JSON (a string containing JSON to be specific) as the data source for a Report. 
TVirtualDataTable seems like the way to go to me. So basically I would use some JSON Parser to create a tree structure from the json string and implement a class based on TVirtualDataTable to access that tree.

Before going down that route I would like to know if you already have some sort of JSON support as a data source on your roadmap (would be cool if I could just pass a json string to AddTable() instead of a datasource or list) and if not, is there more documentation about TVirtualDataTable for the delphi version of flexcel?. I have only found some documentation for the .net version of flexcel but not for delphi (other than the class ref. in the chm help file).

Martin

Hi,
About the documentation in TVirtualDataTable/TVirtualDataTableState you are right that indeed we should provide at least an example. You could actually look at the FlexCel code for the 2 implementations of TVirtualDataTable/TVirtualDataTableState we currently have, but those are probably too complex as a general example. The reason for lack of docs in this part is that well, moving the report engine from .NET (including all the demos) was a huge lot of work, and some stuff that is not really that much used was left out. TVirtualDataTables today aren't as needed as in the v3 era because we can directly use TList<> TArrays<> as datasources.
I do think the idea to add some json support from us (either as a demo or built in) is interesting.

But in the meantime, can't you just load the JSON data in a TDataSet and use that as datasource?  If you have Delphi enterprise, I think FireDAC comes with a mem table that can load JSON directly. I am not sure about other options, but I guess this should be a common feature in TDataSets.

Anyway, a direct way to load json datatables sounds nice, so I'll see if we can add it.





Thanks Adrian,

cool, I'll play with the different options. I used to prefer TList<> in the past over datasets because of the ability to have implicit relations in the TList<>. Only using json would give total flexibility without even having to recompile my application. I could add a new field to the json string and to the report template and that's it. 
Only thing to think about would be to have some convention or configurability for encoding of certain types like date fields and images...

Martin

ok, have successfully created the most simple implementation of a TVirtualDataTable descendant by orienting at TDatasetVirtualTable. TDatasetVirtualTable is pretty straight forward and simple enough.

Now I want to extend my simple implementation to be able to handle not just flat tables but also implicit child lists.
Looking at TVirtualArrayDataTable I now know what you mean with " those are probably too complex as a general example" ... ;-)
Any hint how nested arrays are implemented? Where should I have to look in the code in TVirtualArrayDataTable?

Martin

Just to make sure, I magine you have already, but make sure to read the docs in FlexCel.NET of VirtualDataTable and VirtualDataTableState (the 2 classes you have to implement). They are in appendix II here:
http://www.tmssoftware.biz/flexcel/docs/net/UsingFlexCelReports.pdf
And while for .NET, they are basically the same.

The complexity comes from what you want to support: Stuff like allowing Lookups in the data or Distinct need to implement corresponding methods, but if you don't want, you don't need to implement them. The specific functionality just won't be supported in the report. (for example the user won't be able to use DISTINCT in the config sheet if you don't implement the corresponding method.

To implement implicit child lists you need to override GetRelationWith and return the related tables there.
I'll try to come up with an example for the weekend.