How to stop (cancel) a download using TIdHTTP

I am using the TIdHTTP.Get procedure in a stream to upload a file. My question is, how can I stop (cancel) a file upload?

+4
source share
2 answers

You can use the standard procedure idhttp1.Disconnect ...

+3
source

I would try to undo it by throwing a silent exception using the Abort method in the TIdHTTP.OnWork event . This event is fired for read / write operations, so it is also fired during the boot process.

 type TDownloadThread = class(TThread) private FIdHTTP: TIdHTTP; FCancel: boolean; procedure OnWorkHandler(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Integer); public constructor Create(CreateSuspended: Boolean); property Cancel: boolean read FCancel write FCancel; end; constructor TDownloadThread.Create(CreateSuspended: Boolean); begin inherited Create(CreateSuspended); FIdHTTP := TIdHTTP.Create(nil); FIdHTTP.OnWork := OnWorkHandler; end; procedure TDownloadThread.OnWorkHandler(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Integer); begin if FCancel then begin FCancel := False; Abort; end; end; 

Or, as mentioned here, for a direct disconnect, you can use the Disconnect method in the same case.

 procedure TDownloadThread.OnWorkHandler(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Integer); begin if FCancel then begin FCancel := False; FIdHTTP.Disconnect; end; end; 
+9
source

All Articles