I can't find the email, but I remember Bruno mentioning that I can get the data with an WebHttpRequest and assign it to a WebDataSource. Probably am wrong but I would like to know if that is possible.
Currently I am using the Json string I get from a WebHttpRequest and load it directly to a WebStringGrid. The WebHttpRequests are dynamic and my "get data" functions create and destroy the WebHttpRequests and they are very efficient. I can handle the json strings and load them into the text property of the Edit components. For saving data, my functions use the text properties to compose queries to post back with WebHttpRequests.
.
Also, If I use a chain like this : WebClientConnection -- WebClientDataSet -- WebDataSource -- TMSFNCGridDatabaseAdapter -- TMSFNCGrid, then the data is loaded into the FNC Grid.
Because of all the code base I have made, I would like to load the data from a WebHttpRequest into a FNCGrid, but loading with say, FNCGrid1.loadfromJson does not exist as it does in the regular WebStringGrid.
.
Summarizing my question, is it possible to use the WebHttpRequest to load data into a WebClientConnection, WebDataSet or WebDataSource (or any combination) using some trick?
I tried something similar recently. I asked if there was an easier way, and Bruno suggested I use a TClientDataSet. I tried that and it ran unbelievably slow -- I mean ... 2 seconds vs. 45 seconds! I reported it here and then went back to the previous approach. Later Bruno said they have "improved the performance". But I've found very few examples where typical TDataSets are used in WEB Core apps. They have a HUGE footprint that gets loaded into the browser, and I don't think it's really worth it.
I'm thinking that LiveBindings are a far better way to go with WEB Core apps than TDataSets.
Strangely enough, I've found that ChatGPT is pretty darned good at writing routines to go from one thing to another (ie, import / export routines).
If this is coming from an API that has a swagger profile, you might consider this as an alternative approach, although you're still faced with getting the data in and out of the grid and edit fields. (Which is why I mentioned ChatGPT.)
WebClientConnnection is underlying using WebHttpRequest to fetch the data. So, not sure how you want to use WebHttpRequest separately in combination with WebClientConnection?
If you use WebHttpRequest directly to get a JSON array of data, you should be able to assign it to WebDataSet.Rows
Thanks David, good advise, note taken.
1 Like
Bruno,
Main reason is that I would like to take advantage of my set of functions that handle the web services I programmed, that basically use the WebHttpRequests to post requests in my own encrypted - secured format, and receive back replies in Json text and process them in a very efficient way. With a WebStringGrid is just a matter of loading the grid directly from a json string. But that does not work with the FNC Grid.
I like the "delphi approach" to load a datasource and easily handle the data with related components, like edit, checkbox, navigator, Etc. So If I could use my existing functions for obtaining the data and put it on a dataset that would be perfect.
Secondary reason for my post is that I have not found complete documentation on how to convert from the WebHttpRequest Aresponse (a Json string) to a format or type that I can use to load it into the WebDataSet.rows, which is a TJSArray. I understand the types, but not how to assemble the TJSArray from a Json String in a way that can be accepted into the dataset.rows..
It would help to have a simple example of how a json string keys and values would be in the equivalent TJSarray. Will try to get into the debugger and watch the values and see if I can replicate the structures with a function.
Fastest solution would be to look at the WebClientConnection component source code (in the Core Source subfolder) that does exactly that: perform the HTTP request, get the data as JSON array and assign it to the WebClientDataSet.Rows
If a performance problem remains, please provide details to allow us to reproduce this here so we can investigate.
1 Like
I removed that code and went back to the previous approach. In my case, the only reason was to be able to sort by clicking on the column headers, and I had not realized that the TWebStringGrid allows that. Using data-aware controls just seems like a ton of unnecessary overhead just for this purpose.
Hey David, I think you are right on spot with the opinion that the data aware components footprint is too heavy for some browsers.
I made a concept test this week and definitely there are some issues there, related to performance perhaps, because the issues are intermittent and not predictable.
In comparison, there is no issue with my functions that are with basic WebHttpRequests to get data and post back updates or create new records.
Will polish my concept test app and will post it whenever I can reproduce the issues in a predictable way.
I wanted to use the dataset for the simplicity of using the DB navigator and similar "a la delphi" data, but I can't use them if the results are not as expected, to me at least.
1 Like