Um dem Thread zu signalisieren, dass er aufhören soll rufst du die Methode
Terminate
auf.
Innerhalb des Threads kann man sich in dem Event OnWork einklinken:
Delphi-Quellcode:
type
TDownloadThread = class(TThread)
private
FIdHTTP: TIdHTTP;
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 Terminated then
begin
Abort;
// oder alternativ mit Gewalt die Verbindung kappen
FIdHTTP.Disconnect;
end;
end;