UrlDownloadToFile这个函数怎么用呢?

godc2c 2010-08-24 03:18:45
我在网上找到有关这个函数的使用方法。但是我不明白以下加粗的语句是什么意思。

Delphi 版本:   
uses UrlMon;   
function DownloadFile(SourceFile, DestFile: string): Boolean;  
begin   try   
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;  
//这句怎样理解啊?为什么前面是:= 后面是=0呢? 
except   
Result := False;   
end;   
end;  
 
函数调用:   
if DownloadFile(url, DestFile) then   
begin   
ShowMessage('保存成功!');   
end   else   
begin   
ShowMessage('保存不成功!');   
end;
...全文
2819 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
JPEXE 2010-09-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 learning8899 的回复:]
接宝地问一下UrlDownloadToFile能否实现进度条显示?
[/Quote]
这是API,当然应该看MSDN,http://msdn.microsoft.com/en-us/library/ms775123(VS.85).aspx
learning8899 2010-09-26
  • 打赏
  • 举报
回复
接宝地问一下UrlDownloadToFile能否实现进度条显示?
Frank.WU 2010-08-29
  • 打赏
  • 举报
回复
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;  
//这句怎样理解啊?为什么前面是:= 后面是=0呢?

-----------------
额。。这样写你能不能理解?
if UrlDownloadToFile(...) = 0 then
Result := True
kye_jufei 2010-08-24
  • 打赏
  • 举报
回复
用法:

URLDownloadToFile有五個參數:

第一個參數是僅當調用者是一個ActiveX物件才使用,一般為NULL.

第二個參數就是要下載檔案的目標URL,完整路徑.

第三個是本地保存路徑,也是完整路徑

第四個是保留,必須為0

第五個是指向一個IBindStatusCallback介面的指標,這就類似一種回檔機制,你可以參考這些來活動當前下載進度,選擇是否繼續下載等等.
kye_jufei 2010-08-24
  • 打赏
  • 举报
回复
uses UrlMon; 

begin

try

Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;

except

Result := False;

end;

end;

begin

try

Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;

except

Result := False;

end;

end;

const

// URL Location

SourceFile :=

// Where to save the file

DestFile :=

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;
加入如下代碼:
NMHTTP1.InputFileMode := ture;

NMHTTP1.Body := '本地檔案名';

NMHTTP1.Header := 'Head.txt';

NMHTTP1.OutputFileMode := FALSE;

NMHTTP1.ReportLevel := Status_Basic;

NMHTTP1.Proxy := '代理伺服器的IP位址';

NMHTTP1.ProxyPort := '代理伺服器的埠號';

With NMHTTP1.HeaderInfo do
Begin

Cookie := '';

LocalMailAddress := '';

LocalProgram := '';

Referer := '';

UserID := '用戶名稱';

Password := '用戶口令';

End;
試試吧,Delphi的目錄中有TNMHTTP控制項的例子。NT4+,Win95+,IE3+,你可以用URL Moniker的功能。
uses URLMon; ...
OleCheck(URLDownloadToFile(nil,'URL','Filename',0,nil));

beginio

DownLoadFile:=TFileStream.Create('c:\aa.rar',fmCreate);

DownLoadFile.Free;

end;
//---------------------------

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧