I'm using WinInet to connect and retrieve information from one of our server. I'm using the following:
indexdata: array of byte[1..5000] of byte;
infoBuffer: array [0..5000] of char;
BufferSize: DWORD;
reserved: DWORD;
text: string;
BufferSize := Length(infoBuffer);
res := HttpQueryInfo(hHttpRequest, HTTP_QUERY_RAW_HEADERS_CRLF, @infoBuffer, BufferSize, Reserved);
Reserved := 0;
InternetReadFile(hHttpRequest, @indexdata, sizeof(indexdata), Reserved);
SetLength(text, Reserved);
CopyMemory(@text[1], @indexdata[1], Reserved);
The two array of bytes were enough up until now. Things changed. The server can return now information that can be bigger or smaller than 5000; worst yet, in InternetReadFile can return a variable size in the infoBuffer.
So i tried declaring the indexdata and infobuffer as array of byte and then using SetLength to set its length, but 2 things happened.
1) I still don't know the size of indexdata that the server will return so I cannot properly set it to, say, 100000.
2) I cannot use (as it is now) CopyMemory passing Low(indexdata) to copy indexdata to a simple string variable so I can use the data.
How do I handle this in Delphi? I can do it in C but I can't seem to be able to do it properly in Delphi.
Code is appreciated
thanks!