I setup an NSURLSession with code to:
* create a configuration object and a session based on that object
* a completion handler
It works, sort of. I assign the NSdata and NSresponse to global string variables because I can't eg run ShowMessage in the completion handler because it is not running in the main thread. NSLogging shows the NSdata, NSresponse, NSerror (if there is one) and global variables to which those are assigned all contain the correct content.
But, when I use ShowMessage to display the global variables, the first one (no matter which one I show first) always contains the data with which I initialised the global variable ('default') when it was declared.
I've worked around the issue with:
while((webData = 'default')) AND (webError = 'default') do
Sleep(50);
// display results
if(webErrorReason <> '') then
begin
ShowMessage(webError);
ShowMessage(webErrorReason);
end
else
begin
ShowMessage('Data: ' + LineEnding + webData);
ShowMessage('Response: ' + LineEnding + webResponse);
ShowMessage('Web page: ' + LineEnding + webHTML);
end;
but I don't understand why the issue exists in the first place.
[EDIT]Better work around