0

I'm trying to connect to a REST web service using Delphi 6. I've been able to successfully do this with the code below:

function WSConnect(url: WideString; params: TStringList = nil; method: WideString = 'GET'):WideString; var request: XMLHTTP60; begin // CreateQueryString below just adds any params passed in to the end of the url url := url + CreateQueryString(params); CoInitialize(nil); request := CoXMLHTTP60.Create; request.open(method,url,false,'',''); request.send(''); if request.status=200 then begin Result := request.responseText; end else Result := 'Error: (' + inttostr(request.Status) + ') ' + request.StatusText; CoUninitialize(); end; 

I've pieced together this code from different examples around the net, but I can't find any documentation on CoXMLHTTP60. The code works great, but the current implementation only gives me back a string with the JSON response in it, and I'm struggling to figure out how to pull the properties out of this JSON string in Delphi 6. I've looked at SuperObjects (which people say has problems with Delphi 6 so I didn't try it) and a different project called json4delphi that I couldn't get to compile in Delphi 6 despite it saying it is compatible.

There are also different properties on the CoXMLHTTP60 response object that I believe might get me the values I need. They are:

request.responseBody: OleVariant; request.responseStream: OleVariant; request.responseXML: IDispatch; 

I would think one of these would provide access to the properties in the JSON, but I can't figure out how to even use them. I'm pretty unfamiliar with IDispatch, once again documentation is difficult to find, and what's there looks very confusing. Some places say to just assign the IDispatch property to an OleVariant and then I can access the properties directly with dot notation, but that doesn't seem to be working either for me, so maybe I'm doing it wrong.

Does anyone have any knowledge on how to pull out the response properties in a CoXMLHTTP60 call?

8
  • 3
    The XMLHTTP object has no JSON support. Commented Oct 21, 2020 at 20:31
  • 1
    JSON is a very simple format to parse manually, if you can't find a 3rd party parser that works in D6 (have you tried lkjson or uJSON yet?). Commented Oct 21, 2020 at 21:24
  • @Olivier Ah, that makes sense. So in other words, looking at the other response properties to try to pull out the values is probably a lost cause. Looks like parsing the JSON is my only option, either manually or with a library. Commented Oct 21, 2020 at 22:12
  • 1
    Have you ever considered updating your Delphi to the current version? JSON is supported out of the box. There is Delphi Community Edition which you can use for free (Conditions applies for business) see embarcadero.com/products/delphi/starter/free-download. Commented Oct 22, 2020 at 4:49
  • 1
    @dallin since you have access to a modern Delphi version, an alternative would be to write a DLL in that version that uses Delphi’s native JSON framework to parse the downloaded JSON string, and then you can use that DLL in your Delphi 6 project. Commented Oct 22, 2020 at 7:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.