Перейти к содержанию
Fire Monkey от А до Я

Лидеры

Популярный контент

Показан контент с высокой репутацией 22.01.2021 во всех областях

  1. Вот пример моего потока загрузки Запуск: unit DownloadT; interface uses System.Classes, System.Net.URLClient, System.Net.HttpClient, System.Net.HttpClientComponent, System.SysUtils; type TonDownloadProgress = procedure (Progress:integer) of object; TonDownloadEnd = procedure (FileName:string; Done:boolean; MessageText:string='') of object; TDownloadThread = class(TThread) private IdHTTP1: TNetHTTPClient; fonDownloadProgress:TonDownloadProgress; FonDownloadEnd: TonDownloadEnd; Done: boolean; Max: integer; ProgressValue: integer; procedure ReceiveData(const Sender: TObject; AContentLength:int64; AReadCount:int64; var Abort:boolean); procedure SetonDownloadProgress(const Value: TonDownloadProgress); procedure SetonDownloadEnd(const Value: TonDownloadEnd); protected procedure Execute; override; public url, Status: string; Filename: string; property onDownloadProgress: TonDownloadProgress read FonDownloadProgress write SetonDownloadProgress; property onDownloadEnd: TonDownloadEnd read FonDownloadEnd write SetonDownloadEnd; end; implementation { TDownloadThread } procedure TDownloadThread.Execute; var MyFile: TMemoryStream; begin FreeOnTerminate := true; IdHTTP1 := TNetHTTPClient.Create(nil); MyFile := TMemoryStream.Create(); try IdHTTP1.OnReceiveData := ReceiveData; IdHTTP1.HandleRedirects := true; MyFile.Position := 0; IdHTTP1.Get(url, MyFile); MyFile.SaveToFile(Filename); Done := true; MyFile.Free; IdHTTP1.Free; if Assigned(FonDownloadEnd) then Synchronize(procedure begin FonDownloadEnd(Filename, True); end); except on E:Exception do if Assigned(FonDownloadEnd) then Synchronize(procedure begin FonDownloadEnd(Filename, False, E.Message); end); end; end; procedure TDownloadThread.ReceiveData(const Sender: TObject ; AContentLength:int64 ; AReadCount:int64 ;var Abort:boolean); begin if Terminated then Abort := true else begin Done := false; ProgressValue := AReadCount; if Assigned(fonDownloadProgress) then Synchronize(procedure begin if AContentLength>0 then fonDownloadProgress(Trunc(ProgressValue / AContentLength * 100)) else fonDownloadProgress(0); end); end; end; procedure TDownloadThread.SetonDownloadEnd(const Value: TonDownloadEnd); begin FonDownloadEnd := Value; end; procedure TDownloadThread.SetonDownloadProgress(const Value: TonDownloadProgress); begin FonDownloadProgress := Value; end; end. Запуск: procedure TMainForm.InstallUpdates(aDownloadLink:string); begin DownloadThread:=TDownloadThread.Create(true); DownloadThread.Filename := TPath.Combine(Options.WorkPath,'updates.exe'); DownloadThread.url := aDownloadLink; DownloadThread.onDownloadEnd := OnDownloadEnd; DownloadThread.onDownloadProgress := OnDownloadProgress; DownloadThread.Start;
    1 балл
Эта таблица лидеров рассчитана в Москва/GMT+03:00
×
×
  • Создать...