方法1:
uses urlmon;
{$R *.DFM}
function DownloadFile(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);
begin
if DownloadFile ('http://www.vckbase.com/','c:/index.htm') then
ShowMessage('Download succesful')
else
ShowMessage('Download unsuccesful')
end;
方法2:
用twebbrowser.
procedure TForm1.Button2Click(Sender: TObject);
var
HTMLDocument: IHTMLDocument2;
PersistFile: IPersistFile;
begin
WebBrowser1.Navigate('http://www.vckbase.com/')
HTMLDocument := webbrowser1.Document as IHTMLDocument2;
while HTMLDocument.readyState <> 'complete' do
Application.ProcessMessages; {wait download complete}
PersistFile := HTMLDocument as IPersistFile;
PersistFile.Save(StringToOleStr('c:/tmp/klaus.htm'), system.True);
end;