I am trying to send an array to a webpage but something is wrong.In the DoGet function of a THttpDocument i set the Responce.ContentStream pointing to a memorystream.The script receives a readyState switching between 4 and 1 and the status is always 0.The corresponding DoGet function is called more often than expected. Expected every 5 seconds, sometimes called 10 times per second.After a while no more calls to DoGet are received. (or something got wrong)I don't know if the error is in the pascal code or in the script. Script is mostly copy/paste.Code included. RPI 2BAny advice?

Koen wrote:I don't know if the error is in the pascal code or in the script. Script is mostly copy/paste.Code included. RPI 2BAny advice?

I had a look at your DoGet function, the use of the TMemoryStream seems to be the main cause of the problem.

You have StreamResponse: TMemoryStream declared as a global variable but all you need to do is declare it locally within DoGet and then create a new instance of it every time Action = OFF is called.

Instances of classes in Free Pascal are not reference counted and are not automatically destroyed when they go out of scope, so it is quite ok to create an instance of TMemoryStream locally within a function like DoGet and pass it to something else for later use as long as you know that something else will also free the stream when it is done.

Here's the relevant part of the DoGet function modified so that the memory stream works correctly:

After these changes it doesn't crash anymore and will keep running for as long as you leave it on the page, the JavaScript still doesn't seem to like your array (shows "undefined") but I'll leave that for you to work out.

Good advice!I made the changes as you proposed.Now I get a response with the expected length.The new problem is the response type is string as I found out by using typeof(xmlhttp.response) in the script.I do set xmlhttp.responceType = 'arraybuffer' in the script.

I took a look at the HTTP unit and line 2366, wich sets the header for a stream content, isSetHeader(HTTP_ENTITY_HEADER_CONTENT_TYPE,HTTP_CONTENT_TEXT_HTML);Could that be the reason?I guess I can find a workaround for the script but will wait for your answer first.

Koen wrote:The new problem is the response type is string as I found out by using typeof(xmlhttp.response) in the script.I do set xmlhttp.responceType = 'arraybuffer' in the script.

I took a look at the HTTP unit and line 2366, wich sets the header for a stream content, isSetHeader(HTTP_ENTITY_HEADER_CONTENT_TYPE,HTTP_CONTENT_TEXT_HTML);Could that be the reason?I guess I can find a workaround for the script but will wait for your answer first.

You can set your own content type by simply calling AResponse.SetHeader in your DoGet method.

There is no need setting the responsetype on the Ultibo side.I tried both leaving it to default and setting it to 'application/octet-stream'.Makes no difference on the script side.Everything is working as espected now.Thanks again!Background: it 's the base code for a scope-object for my Pluteus project. Shows the process-values.