全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2430
推到 Plurk!
推到 Facebook!

如何用程式從網頁下載一個檔案?

 
領航天使
站長


發表:12216
回覆:4186
積分:4084
註冊:2001-07-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-04-26 08:37:10 IP:61.219.xxx.xxx 未訂閱
//如何用程式從網頁下載一個檔案? 回答: 有很多方法可以達成,以下是一個很方便的辦法不使用元件,但要記得 USES ShellApi,UrlMon; 這個範例抓取 http://www.hinet.net/images/hinet_logo.gif圖檔至c:\hinet.gif中存檔,並呼叫出來顯示. P.S:附原始程式供下載參考.    
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,shellapi,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 DownLoadInternetFile(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
  SourceString, DestinationString: string;
begin
//網頁檔案網址
  SourceString := 'http://www.hinet.net/images/hinet_logo.gif';
//存檔位址
  DestinationString := 'C:\hinet.gif';      if DownLoadInternetFile(SourceString, DestinationString) then
//呼叫檔案出來執行或顯示
    ShellExecute(Application.Handle, PChar('Open'), PChar(DestinationString), PChar(''), nil, SW_NORMAL)
  else
    ShowMessage('Error during Download '   SourceString);
end;
end.
~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~
附加檔案:00018128_test.zip
系統時間:2024-04-30 18:37:25
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!