este es un componente que encontre en internet tenias unos errores que corregi pero ahora me funciona lo unico que el componente no se comunica
diciendome cuando termina la descarga ni cuantos bytes esta bajando si alguien me puede dar una mano se lo agradesco
Código:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Buttons, IndyDownloads, ExtCtrls;
type
TForm1 = class(TForm)
URL: TEdit;
Redirections: TUpDown;
Edit2: TEdit;
Edit3: TEdit;
Debit: TUpDown;
Edit4: TEdit;
Tentatives: TUpDown;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
StatusBar1: TStatusBar;
Demarrer: TBitBtn;
ProgressBar1: TProgressBar;
Fichier: TEdit;
Label1: TLabel;
Button1: TButton;
SaveDialog1: TSaveDialog;
Arreter: TBitBtn;
Retenter: TBitBtn;
Pause: TBitBtn;
Label6: TLabel;
Timer1: TTimer;
procedure DemarrerClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure IndyDownloads1Succeeded(Sender: TComponent;
IndyDownloadableFile: TIndyDownloadableFile);
procedure IndyDownloads1Failed(Sender: TComponent;
IndyDownloadableFile: TIndyDownloadableFile);
procedure IndyDownloads1Work(Sender: TComponent;
IndyDownloadableFile: TIndyDownloadableFile);
procedure IndyDownloads1Suspended(Sender: TComponent;
IndyDownloadableFile: TIndyDownloadableFile);
procedure ArreterClick(Sender: TObject);
procedure RetenterClick(Sender: TObject);
procedure PauseClick(Sender: TObject);
procedure IndyDownloads1Redirect(Sender: TComponent;
IndyDownloadableFile: TIndyDownloadableFile);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
IndyDownloads1: TIndyDownloads;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin if SaveDialog1.Execute then Fichier.Text:=SaveDialog1.FileName; end;
procedure TForm1.DemarrerClick(Sender: TObject);
begin
if IndyDownloads1 = nil then
IndyDownloads1:=TIndyDownloads.Create(self);
IndyDownloads1.DownloadableFileList.Clear;
ProgressBar1.Position:=0;
StatusBar1.SimpleText:='En curso...';
Demarrer.Enabled:=false; Arreter.Enabled:=true; Retenter.Enabled:=false; Pause.Enabled:=true;
// Cada descarga (treahd) debe estar asociada con un identificador único para garantizar la coherencia con el hilo principal
IndyDownloads1.DownloadableFileList.Add(TIndyDownloadableFile.Create(URL.Text, Fichier.Text, IndyDownloads1.GetNextUniqueID, Debit.Position, Tentatives.Position, Redirections.Position));
// Ponemos en marcha la descarga
TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).Start;
end;
procedure TForm1.IndyDownloads1Succeeded(Sender: TComponent; IndyDownloadableFile: TIndyDownloadableFile);
begin
StatusBar1.SimpleText:='Termino';
Demarrer.Enabled:=true; Arreter.Enabled:=false; Retenter.Enabled:=false; Pause.Enabled:=false;
end;
procedure TForm1.IndyDownloads1Failed(Sender: TComponent; IndyDownloadableFile: TIndyDownloadableFile);
begin
StatusBar1.SimpleText:='Error';
Demarrer.Enabled:=true; Arreter.Enabled:=true; Retenter.Enabled:=true; Pause.Enabled:=false;
end;
procedure TForm1.IndyDownloads1Work(Sender: TComponent; IndyDownloadableFile: TIndyDownloadableFile);
begin
ProgressBar1.Max:= TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).TotalFileSize;
ProgressBar1.Position:=TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).BytesDownloaded;
end;
procedure TForm1.IndyDownloads1Suspended(Sender: TComponent; IndyDownloadableFile: TIndyDownloadableFile);
begin
Demarrer.Enabled:=true; Pause.Enabled:=false;
if IndyDownloadableFile.State=si_Paused then
begin
StatusBar1.SimpleText:='Suspendido';
Arreter.Enabled:=true; Retenter.Enabled:=true;
end
else
begin
StatusBar1.SimpleText:='Parado';
Arreter.Enabled:=false; Retenter.Enabled:=false;
end;
end;
procedure TForm1.ArreterClick(Sender: TObject);
begin
if Assigned(IndyDownloads1.DownloadableFileList[0]) and
(TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).State in [si_Downloading, si_Failed]) then
TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).Stop;
Demarrer.Enabled:=true; Arreter.Enabled:=false; Retenter.Enabled:=false; Pause.Enabled:=false;
ProgressBar1.Position:=0; StatusBar1.SimpleText:='';
end;
procedure TForm1.RetenterClick(Sender: TObject);
begin
if Assigned(IndyDownloads1.DownloadableFileList[0]) and
(TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).State in [si_Paused, si_Failed]) then
begin
TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).Resume;
StatusBar1.SimpleText:='En curso...';
end;
Demarrer.Enabled:=false; Arreter.Enabled:=true; Retenter.Enabled:=false; Pause.Enabled:=true;
end;
procedure TForm1.PauseClick(Sender: TObject);
begin
if Assigned(IndyDownloads1.DownloadableFileList[0]) and
(TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).State=si_Downloading) then
TIndyDownloadableFile(IndyDownloads1.DownloadableFileList[0]).Pause;
Demarrer.Enabled:=false; Arreter.Enabled:=true; Retenter.Enabled:=false; Pause.Enabled:=false;
end;
procedure TForm1.IndyDownloads1Redirect(Sender: TComponent; IndyDownloadableFile: TIndyDownloadableFile);
begin
StatusBar1.SimpleText:='Redirection : '+IndyDownloadableFile.URL;
end;
end.