0
votes

I am using Delphi 10.1 Berlin update and Indy's TIdHttp component. I usually abort a connection using the following code:

procedure TMyThread.OnWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: int64);
begin
    if abort then (asender as tidhttp).Disconnect;
end;

This works fine in a VCL application, also in a FireMonkey application as long the platform is Windows. When I use this code with MacOS as target, it close my application instantly without error message or anything displayed.

So my question here is what am I doing wrong, and how can I abort a connection when the platform is MacOS?

2
FireMonkey has been plagued with exception handling issues on OSX for years. There are numerous reports in QualityCentral related to runtime error 231. AFAIK, a root cause was never found, but has been acknowledged as a problem.Remy Lebeau
use modern THTTPClient instead of IndyZam
@Zam - I have to stick with Indy, I cant change the huge amount of functions to something else for now.user7415109
So I can test this properly, what is the idHTTP control doing at the time you want to cancel? (Connecting, downloading, etc).MikeD
THttpClient has also issues. I have some sites when accessing them via THttpClient, I get after a while an error that the sire redirected too much or something like that. Using indy. it did not even redirect once for the same urls.user7415109

2 Answers

3
votes

Rather then call Disconnect() directly and rip the socket connection away from TIdHTTP, I would raise an exception instead, like calling SysUtils.Abort(), and let TIdHTTP or the calling thread close the socket after the request has been fully aborted.

procedure TMyThread.OnWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: int64);
begin
  if Self.Abort then SysUtils.Abort;
end;

procedure TMyThread.Execute;
var
  HTTP: TIdHTTP;
begin
  HTTP := TIdHTTP.Create;
  try
    ...
  finally
    HTTP.Free;
  end;
end;
0
votes

try like this :

procedure TMyThread.OnWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: int64);
begin
  try  
    if abort then (asender as tidhttp).Disconnect;
  except
  end;
end;