If I run the below code three times ( on a button first instance), on the third time it will fail with an error of undefined, it appears not to populate the field definitions or the webclientdataset correctly but only on third occurence, the showmessage function displays the json i am expecting evertime so it is something to do with the dataset that is causing the error. Is there something else I should be doing?
Try
ServiceRequest := TWebHttpRequest.Create(nil);
ServiceRequest.Url := ServiceURL;
req := await(TJSXMLHttpRequest, servicerequest.Perform());
showmessage(string(req.response));
dataset.close;
dataset.fields.Clear;
dataset.Rows := TJSArray(TJSJSON.parseObject(req.responseText));
dataset.Open;
finally
Servicerequest.free;
end;