L
luqiao
Unregistered / Unconfirmed
GUEST, unregistred user!
函数如下(大富翁里借用的):
function tfxz.UrlGetFile(URL, AFile: string; v: boolean): integer;
var
hFile, HInet: HINTERNET;
Buffer: array[0..511] of Char;
BufRead: Cardinal;
BufSize: Cardinal;
fs: tfilestream;
begin
Result := 0;
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);
fs := TFileStream.Create(AFile, fmCreate);
with fs do
try
while (not downbool) and (InternetReadFile(hFile, @Buffer, BufSize, BufRead)) and (BufRead > 0) do
begin
Write(Buffer, BufRead);
if v then
begin
application.ProcessMessages;
fxz.ProgressBar1.Position := fs.Size * 100 div sjsize;
fxz.label3.caption := inttostr(fs.size);
end;
end;
Result := fs.Size;
finally
Free;
end;
finally
InternetCloseHandle(hFile);
end;
finally
InternetCloseHandle(hinet);
end;
end;
主FORM create就开始做:
if urlgetfile('http://game.d3xvet.com/web/zc.txt', 'zc.txt', false) = 0 then
begin
msgbox1('网络', '服务器忙' + #13 + '请重新登录', 1,suiinformation);
application.Terminate;
exit;
end;
如果下载不成功就直接提示并退出,问题怪在如果我刚开机器就直接运行这个程序,一定是下载不到文件的,必须开一下IE浏览器以后(以后可以关掉IE)才能下载到,为什么要调用IE来做个初始化呢?不调IE的话怎么在程序里解决?
盼急救!
function tfxz.UrlGetFile(URL, AFile: string; v: boolean): integer;
var
hFile, HInet: HINTERNET;
Buffer: array[0..511] of Char;
BufRead: Cardinal;
BufSize: Cardinal;
fs: tfilestream;
begin
Result := 0;
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);
fs := TFileStream.Create(AFile, fmCreate);
with fs do
try
while (not downbool) and (InternetReadFile(hFile, @Buffer, BufSize, BufRead)) and (BufRead > 0) do
begin
Write(Buffer, BufRead);
if v then
begin
application.ProcessMessages;
fxz.ProgressBar1.Position := fs.Size * 100 div sjsize;
fxz.label3.caption := inttostr(fs.size);
end;
end;
Result := fs.Size;
finally
Free;
end;
finally
InternetCloseHandle(hFile);
end;
finally
InternetCloseHandle(hinet);
end;
end;
主FORM create就开始做:
if urlgetfile('http://game.d3xvet.com/web/zc.txt', 'zc.txt', false) = 0 then
begin
msgbox1('网络', '服务器忙' + #13 + '请重新登录', 1,suiinformation);
application.Terminate;
exit;
end;
如果下载不成功就直接提示并退出,问题怪在如果我刚开机器就直接运行这个程序,一定是下载不到文件的,必须开一下IE浏览器以后(以后可以关掉IE)才能下载到,为什么要调用IE来做个初始化呢?不调IE的话怎么在程序里解决?
盼急救!