Урок на Делфи 68. Индикатор загрузки файла по http
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, Vcl.StdCtrls, Vcl.ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
IdHTTP1: TIdHTTP;
ProgressBar1: TProgressBar;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
procedure IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
size_file:Int64;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
s:TMemoryStream;
begin
Label1.Caption:=IntToStr(size_file);
ProgressBar1.Max:=size_file;
Memo1.ScrollBars:=ssBoth;
s := TMemoryStream.Create;
IdHTTP1.Get('http://dear-ruslan.ru/new/inventory_rep/site/ruslan599E6_all.txt', s);
s.Position := 0;
Memo1.Lines.LoadFromStream(s);
Label1.Caption:=IntToStr(s.Position);
s.Free;
end;
procedure TForm1.IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
begin
progressBar1.Position:=AWorkCount;
end;
procedure TForm1.IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
begin
size_file:=AWorkCountMax;
ProgressBar1.Max:=AWorkCountMax;
end;
end.