Skip to content

Instantly share code, notes, and snippets.

@HemulGM
Created March 10, 2020 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HemulGM/cc86529315ede9e4ce03ebab9cddeabf to your computer and use it in GitHub Desktop.
Save HemulGM/cc86529315ede9e4ce03ebab9cddeabf to your computer and use it in GitHub Desktop.
unit Unit3;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, System.Types, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, System.Net.HttpClient, Vcl.StdCtrls;
type
TForm3 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure OnReceiveData(const Sender: TObject; AContentLength, AReadCount: Int64; var Abort: Boolean);
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.OnReceiveData(const Sender: TObject; AContentLength: Int64; AReadCount: Int64; var Abort: Boolean);
begin
Memo1.Lines.Add(Round(100 / AContentLength * AReadCount).ToString + '%');
Application.ProcessMessages;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
HTTP: THTTPClient;
FS: TFileStream;
Url: string;
begin
FileClose(FileCreate('D:\tmp\file.tmp'));
FS := TFileStream.Create('D:\tmp\file.tmp', fmOpenReadWrite);
Url := 'https://vk.com/doc-51529633_233391193?dl=985345b6c76e14d803';
HTTP := THTTPClient.Create;
HTTP.OnReceiveData := OnReceiveData;
HTTP.Get(Url, FS);
FS.Free;
HTTP.Free;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment