单击按钮,然后直接从www.hongyuncp.com下载文件,比如"temp.mdb"
这个代码怎么写啊???

解决方案 »

  1.   

    urldownloadtofile
    uses加上UrlMon.pas
      

  2.   

    Uses URLMon, ShellApi; 
    function DownloadFile(SourceFile, DestFile: string): Boolean; 
    begin 
    try 
    Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0; 
    except 
    Result := False; 
    end; 
    end; procedure TForm1.Button1.Click(Sender: TObject); 
    const 
    // URL Location 
    SourceFile := ''/Article/UploadFiles/200509/20050925235700658.gif''; 
    // Where to save the file 
    DestFile := ''c:\temp\google-image.gif''; 
    begin 
      if DownloadFile(SourceFile, DestFile) then 
      begin 
        ShowMessage(''Download succesful!''); 
        // Show downloaded image in your browser 
    ShellExecute(Application.Handle,PChar(''open''),PChar(DestFile),PChar(''''),nil,SW_NORMAL) 
      end 
      else 
      ShowMessage(''Error while downloading '' + SourceFile) 
    end;  
      

  3.   


    function TForm1.DownloadFile(SourceFile, DestFile: string): Boolean;
     var
      hasError: boolean;
     begin
       hasError:=false;
      with TDownloadURL.Create(self) do
       try
         URL:=SourceFile;//要下载的文件,如:'www.hongyuncp.com/temp.mdb'
         FileName := DestFile;//本地保存位置
         isdowning:=True;
         OnDownloadProgress := URL_OnDownloadProgress;//如果需要进度显示,就要写这句话
         ExecuteTarget(nil) ;
       except on e: Exception do
        begin
          ShowMessage(e.Message);
          Free;
          hasError:=true;
        end;
       end;
       Result := not hasError;
     end;进度显示的procedure TForm1.URL_OnDownloadProgress(Sender: TDownLoadURL; Progress,
      ProgressMax: Cardinal; StatusCode: TURLDownloadStatus; StatusText: String;
      var Cancel: Boolean);
    begin
        g1.MaxValue:=ProgressMax;//进度条的最大值
        g1.Progress:=Progress;//当前进度
        Application.ProcessMessages;
        Cancel:=not isdowning;//判断用户是否点击了取消
    end;
    uses
    extActns很详细了吧,其他的不说咯