//----------------------------------------------------------------------------
//urlgetfile函数,下载一个文件
function GetUrlFile(const URL, AFile: string): Boolean;
var
hFile,HInet:HINTERNET;
Buffer:array[0..32767] of Char;
BufRead:Cardinal;
BufSize:Cardinal;
begin
Result := False;
HInet := InternetOpen('Agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(HInet) then
try
hFile := InternetOpenUrl(HInet, PChar(URL), nil, 0, INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION, 0);
if Assigned(hFile) then
try
BufSize := SizeOf(Buffer);
with TFileStream.Create(AFile, fmCreate) do
try
while InternetReadFile(hFile, @Buffer, BufSize, BufRead) and (BufRead > 0) do
Write(Buffer, BufRead);
Result := True;
finally
Free;
end;
finally
InternetCloseHandle(hFile);
end;
finally
InternetCloseHandle(hinet);
end;
end;