Sollte eigentlich so funktionieren.
Delphi-Quellcode:
function TMainForm.GetTHTTPClient ( Const xURL : String ) : String;
var
tmp : String;
MyThread: TThread;
TimeOut: Cardinal;
begin
tmp := '';
MyThread := TThread.CreateAnonymousThread(
procedure
var
HttpClient: THttpClient;
HttpResponse: IHttpResponse;
begin
tmp := '';
HttpClient := THTTPClient.Create;
try
HttpResponse := HttpClient.Get( xURL );
tmp := HttpResponse.ContentAsString();
finally
HttpClient.Free;
end;
end
);
MyThread.FreeOnTerminate := True;
TimeOut := GetTickCount;
MyThread.Start;
repeat
Application.ProcessMessages;
Sleep(5);
until (tmp<>'') or ((GetTickCount-TimeOut)>5000); //neu
Result := tmp;
end;