Scaricare file dalla rete con delphi

Se si ha bisogno di salvare il cuntenuto di un URL oppure un vero e proprio file presente in rete avendo anche la possibilità di controllare come procede il download, bisogna usare l’action TDownLoadURL. Essa genera un evento OnDownloadProgress, che consente di tenere traccia dei byte scaricati.
Nota: bisogna includere la unit ExtActns nella uses.

uses ExtActns, ...
 
type
TfrMain = class(TForm)
...
private
    procedure URL_OnDownloadProgress
       (Sender: TDownLoadURL;
        Progress, ProgressMax: Cardinal;
        StatusCode: TURLDownloadStatus;
        StatusText: String; var Cancel: Boolean);
...
 
 
implementation
...
 
 
procedure TfrMain.URL_OnDownloadProgress;
  begin
    ProgressBar1.Max:= ProgressMax;
    ProgressBar1.Position:= Progress; 
  end;
 
function DoDownload;
  begin
    with TDownloadURL.Create(self) do
    try
      URL:='http://www.prova.com/index.xml';
      FileName := 'c:\MioFile.xml';
      OnDownloadProgress := URL_OnDownloadProgress;
      ExecuteTarget(nil);
    finally
    Free;
    end;
  end;

Articoli simili

  • Articoli simili
  1. ely88
    Posted novembre 22, 2007 at 5:55 pm

    Ciao!!!
    nel TdownloadURL.create(self) non mi riconosce self… cosa posso fare??
    e poi doDownload è una funzione?? cosa ritorna?? oppure è una procedura che si avvia xes con il click di un bottone??
    spero che mi risp

Lascia un commento

Your email is never published nor shared. Required fields are marked *

*
*

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a