procedure TForm1.BStartClick(Sender: TObject);
begin
ProgressBar1.Max := SLRepairFiles.Count;
DownLoader_Thread := TDownLoader_Thread.Create(True);
DownLoader_Thread.FSLRepairFiles := SLRepairFiles;
DownLoader_Thread.FreeOnTerminate := True;
DownLoader_Thread.Resume;
end;
procedure TDownLoader_Thread.Execute;
var
HTTP: TIdHTTP;
FS: TFileStream;
i: Integer;
Folder: string;
begin
HTTP := TIdHTTP.Create(nil);
CriticalSection.Enter;
for i := 0 to FSLRepairFiles.Count - 1 do
begin
if Self.Terminated then Break; // Если главный поток приказал - умираем
Folder := ExtractFilePath(Application.ExeName) + ExtractFilePath(FSLRepairFiles.Strings[i]);
ForceDirectories(Folder);
try
try
FS := TFileStream.Create(Folder + ExtractFileName(FSLRepairFiles.Strings[i]), fmCreate);
HTTP.Get('http://77.108.194.247/' + FSLRepairFiles.Strings[i], FS);
except
end;
finally
FS.Free;
end;
Progress := i + 1;
Synchronize(SyncProc);
end;
CriticalSection.Leave;
HTTP.Free;
end;
procedure TDownLoader_Thread.SyncProc;
begin
Form1.ProgressBar1.Position := Progress;
if FSLRepairFiles.Count = Progress then Form1.Caption := 'Восстановлено: ' + IntToStr(FSLRepairFiles.Count) + ' файлов';
end;
procedure TForm1.BStopClick(Sender: TObject);
begin
DownLoader_Thread.Terminate;
DownLoader_Thread.WaitFor; // Ждём, когда DownLoader_Thread "мирно" помрёт
DownLoader_Thread.Free;
end;
Где моя ошибка?