load response of TwebHttpRequest direct into

Sorry for blank error submission, here is my question ,

Hi , if i need to optimize traffic for my application to fetch using
TwebHttpRequest and then upon receive of the response from my backend server
i need to use it for TwebClientDataset for screen /data control navigation
(let say i prefer to use TWebClientDataset for manipulation of my records instead
of JSON object) ,
is there a way for us to load the response directly into TWebClientDataset ?
If you use the latest version of TMS WEB Core, you can set TWebClientDataSet.Rows := TJSArray and then open the dataset, with TJSArray the JSON array for the dataset that was retrieved via the request response.

Hi , can i get some advice on how to get my response as string and convert to TJSArray ?


procedure TDMConnection.RestRequestConnRequestResponse(Sender: TObject;
  ARequest: TJSXMLHttpRequest; AResponse: string);
var _AResponse :string ;
    _jsArray : TJSArray;
begin

   _AResponse := AResponse;
   _jsArray := ???? how to convert my AResponse to jsArray ????

   
   asm

   end;

   ShowMessage( 'on request Response '+_AResponse );
end;

var
  _jsArray: TJSArray;
begin
    _jsArray := TJSArray(TJSJSON.parseObject(AResponse));
end;

Thanks for the info ,can i find out whether there is document available for learning how to manipulate TJSArray ?

e.g. 
1. how to loop the items in the array and get its value ?
2. how to get some of  the items in the array which the value is object ? 
3. how to find direct the name of the item and get its value ?
    i saw there is a function like find , findindex , every ... etc.

thanks.

You can see this class definition in JS.PAS and it actually maps directly onto the JSArray JavaScript object.

https://www.w3schools.com/jsref/jsref_obj_array.asp

if my AResonse string is something like this


   AResponse =  "{"count": 0, "model": "message", "data": [ { "id": 1 } ,{ "id": 2 } ] }"  

if i code as per your advice ,which is to convert the AResponse string to JSArray ,
can u pls provide a sample on how do i extract the array values/key pair in the "data" , in order for me to do the following , 

TWebClientDataSet.Rows := TJSArray and then open the dataset  ? (because , i presume that the Rows will only be interested in the data ARRAY in my Aresponse JSArray)

and how do i get the value of count ? model ?

Your response is not an array, only data is an array. So, please parse this as JSONObject and then get the different object property values (in pretty much the same way as you would directly do in Delphi)

oh i see , thanks,  got an idea , pass the AResonse into ASM block and use JS to do the conversion ,this can be done , only in TMS Webcore way  !


i.e. JSON.parse(  AResponse ) ;then manipulate the result. 

You can of course handle it in an ASM block but we strive here to handle as much as possible using Pascal code since the purpose of TMS WEB Core is to bring Object Pascal to the web :)

Hi Bruno , i tested with a simple load of the following code following what you advice but the dataset will not open , anything i missed ?


 MyDataset1.Rows := TJSArray(TJSJSON.parseObject('[{"id":1,"name":"group1"}]') );
 MyDataset1.Open;

then at the myDataset1.afterOpen event , i put
   showmessage(inttostr( dataset.recordcount ));

but the afterOpen event never get fired ! is my above code correct ?


Was retested with a TwebClientDataSet on the form and the code:


procedure TForm3.WebButton1Click(Sender: TObject);
begin
 WebClientDataSet1.Rows := TJSArray(TJSJSON.parseObject('[{"id":1,"name":"group1"}]') );
 WebClientDataSet1.Open;
end;

procedure TForm3.WebClientDataSet1AfterOpen(DataSet: TDataSet);
begin
  caption := inttostr(webclientdataset1.recordcount);
end;

and this shows in the browser window title : '1'

i faced very weird behavior , i am now stuck here and cannot proceed ,need to find a solutions ,


1. the only difference mine code and yours is i put it in the web datamodule . so i simulate
    your code , put the webclientdataset on one of my  FORM , 
    but it still cannot open , is my local TMS webcore version
    different from yours ? (mine 1.1.3.0 )

2. when i commented out the 2 lines , my Chrome console report no error , and there is no event for
    my webclientdataset that can potentially caused this error , 
    but when i use this 2 lines of code, Chrome console will report
    errors and will not execute those codes after the webClientDataset1.open ,
    my 2 lines of code are as follow , and i put it in my TWebTimer ,OnTimer event ,

   WebClientDataSet1.Rows := TJSArray(TJSJSON.parseObject('[{"id":1,"name":"group1"}]') );
   WebClientDataSet1.Open;

   ... there are some more code after the above and i put break point and it never beyond the above ...

3. As i mentioned , my chrome console reported error , but i click on the myproject.js file reported there , it never show anything on the right panel , it showed Number OF errors on the left ,  just wish to check what Error has been reported but cannot, not sure how do i get help on this ? 

is there a remote support available from your end , so u can log into my PC to take a look ?
(email to me if there is a cost for it , thanks.)

I solved the no 3 item by clicking on the Pause on exceptions option and i think now the 2 Error stop at the point of exception,  


and then another stopped at ...



but i still have no clue why the 2 errors reported , as my code did pass the correct array same as your advice.

You can download the test project with which we do not see any issue here via:

http://www.tmssoftware.net/public/WebCoreClientDataSetTest.zip 

Hi downloaded and compiled , execute without making any changes but

i cannot run it , as it throw error !



Please advice , thanks.

I can only suspect you still have older version files around on your system.
Make sure you have a clean install of only the latest version.

do u have any advice for me to try to look for and files and make sure i have a clean installation of the TMS Webcore ?

like what are the files found ?

Hi , quite desperate, i uninstalled TMS Webcore , redownload it , clean up all folders , delete it from whatever location that i can find on my pc , but after reinstall , compile the project , still face the same issue ! it is very important for me to be able to do 


   MyDataset1.Rows := TJSArray(TJSJSON.parseObject('[{"id":1,"name":"group1"}]') );

thanks.
For me, the same.
Additionally, Rows and parseObject are not recognized.
Delphi 10.3.1 Rio.
https://snag.gy/2Qz4tI.jpg
https://snag.gy/qPOZQn.jpg