Delphi Seattle...
I have a RestClient, RequestRequest, RestResponse, ResetResponseDataSetAdapter, Datasource, and ClientDataSet all tied together. This configuration works on my development machine, but not on a standard PC. When I delete the RestResponseDataSetAdater, Datasource and ClientDataSet, then the REST call works fine and I can dump the JSON text out to a memo (on all computers), so I know the REST call is working. There is something about those 3 components that works on my development machine, but not a non-development machine.
All 6 components are on a datamodule, called dmREST. It is a test app that only makes this one call, iterates through the Dataset, and writes the values to a TListView. Everything works fine on my development box. The ONLY way I can get it to work on any other computer is to remove the RestResponseDataSetAdater, Datasource and ClientDataSet. Here are the applicable portions of code.
From the button to start the call...The TListView is called UserRequests.
procedure TForm1.Button1Click(Sender: TObject);
var
myCursor: TCursor;
RequestCount: Integer;
vNewItem: TListItem;
baseURL, resource, suffix: String;
begin
UserRequests.Clear;
myCursor := Screen.Cursor;
Screen.Cursor := crSQLWait;
// Call the REST API
baseURL := 'https://<removed due to security>/product';
resource := 'egrapher_request';
suffix := '1234';
if dmREST.restGET(baseURL, resource, suffix) = true then
begin
dmREST.ds1.DataSet.First;
RequestCount := dmREST.ds1.DataSet.RecordCount;
while not dmREST.ds1.DataSet.Eof do
begin
vNewItem := UserRequests.Items.Add;
vNewItem.Caption := dmREST.ds1.DataSet.FieldByName('email').AsString;
vNewItem.SubItems.Add(dmREST.ds1.DataSet.FieldByName('request_date').AsString);
dmREST.ds1.DataSet.Next;
end;
end;
Screen.Cursor := myCursor;
end;
Within the Datamodule...
function TdmREST.restGET(baseURL, resource, suffix: String) : Boolean;
begin
dmREST.RESTResponseDataSetAdapter1.FieldDefs.Clear;
dmREST.RESTRequest1.ResetToDefaults;
dmREST.RESTResponse1.ResetToDefaults;
try
// Now set up the REST Controls...
dmREST.RESTClient1.baseURL := baseURL;
dmREST.RESTRequest1.Method := TRESTRequestMethod.rmGET;
dmREST.RESTRequest1.resource := resource;
dmREST.RESTRequest1.ResourceSuffix := suffix;
// Call the REST API to delete the data
RESTRequest1.Execute;
Result := True;
except
MessageDlg('Unable to connect. Probably not on VPN network', mtError, [mbOK], 0);
ShowMessage(IntToStr(RESTResponse1.StatusCode) + ':' + RESTResponse1.StatusText);
Result := False;
end;
end;
I have tried this with and without the 'ResetToDefaults' code. Although the Exception fires, it always comes back with 200:OK.
There is something about the parsing of the JSON that is causing the issue, but it is only on the non-development boxes.
TFDMemTableif you can. - Victoria