delphi下载文件,delphi从http服务器上下载文件

delphi下载文件,delphi从http服务器上下载文件_第1张图片

unit downloadTest;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,UrlMon;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
  //文件下载
function DownloadFile(Source, Dest: string): Boolean;
begin 
  try 
    Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0; 
    except 
      Result := False; 
    end; 
  end;

procedure TForm1.Button1Click(Sender: TObject);
var filedir,downloadUrl:string;
begin
    filedir :='D:\delphi\download\client.zip';
    downloadUrl :='http://download.pingan.com.cn/bank/client.zip';
    if  DownloadFile(downloadUrl,filedir) then
      showMessage('文件下载成功')
    else
      showMessage('文件下载失败');
end;

end.


你可能感兴趣的:(delphi下载文件,delphi从http服务器上下载文件)