我正在使用TWebBrowser为我的程序构建一个更新程序。OnCreate TWebBrowser导航到给定的URL。要下载更新,用户必须单击链接。单击该链接时,将显示此弹出窗口:

所以我想知道是否有可能:
弹出并允许自动下载的
的固定路径。
发布于 2012-01-21 02:08:35
TWebBrowser不是您想要的,因为您没有显示活动的HTML。如前所述,还有许多其他选择。基本上,您需要一个HTTP请求。
下面是一个非常简单的使用WinInet的例子,它需要适应您的需要(线程、状态消息等等)。
function DownloadURL(inURL, destfile: string): boolean;
var
hOpen: HINTERNET;
hFile: HINTERNET;
myAgent: string;
savefile: file;
amount_read: integer;
// the buffer size here generally reflects maximum MTU size.
// for efficiency sake, you don't want to use much more than this.
mybuffer: array[1..1460] of byte;
begin
Result := true;
myAgent := 'Test downloader app';
// other stuff in this call has to do with proxies, no way for me to test
hOpen := InternetOpen(PChar(myAgent), 0, nil, nil, 0);
if hOpen = nil then
begin
Result := false;
exit;
end;
try
hFile := InternetOpenURL(hOpen, PChar(inURL), nil, 0,
INTERNET_FLAG_RELOAD or INTERNET_FLAG_DONT_CACHE, 0);
if hFile = nil then
begin
Result := false;
exit;
end;
try
AssignFile(savefile, destfile);
Rewrite(savefile, 1);
InternetReadFile(hFile, @myBuffer, sizeof(mybuffer), amount_read);
repeat
Blockwrite(savefile, mybuffer, amount_read);
InternetReadFile(hFile, @myBuffer, sizeof(mybuffer), amount_read);
until amount_read = 0;
CloseFile(savefile);
finally
InternetCloseHandle(hFile);
end;
finally
InternetCloseHandle(hOpen);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
// example usage.
begin
if SaveDialog1.Execute then
begin
if DownloadURL(Edit1.Text, SaveDialog1.FileName) then
ShowMessage('file downloaded.')
else
ShowMessage('Error downloading file.');
end;
end;https://stackoverflow.com/questions/8949965
复制相似问题