Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
Delphi 6 Personal
|
Re: Datei downloaden?
17. Jul 2005, 14:42
So:
Delphi-Quellcode:
// ...für die bei denen die Online Hilfe von Delphi (PE) streikt.
// uses ..., WinINet;
// CopyURL('http://www.Samples.com/Images/Image001.jpg', 'C:\Downloaded_Image001.jpg')
function CopyURL( const URL, OutputFile: string): Boolean;
const
BufferSize = 2048;
var
hSession, hURL: HInternet;
Buffer: array[0..Pred(BufferSize)] of Byte;
BufferLength: DWORD;
f: file;
m: tmsg;
begin
Result := False;
hSession := InternetOpen(' User', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
try
hURL := InternetOpenURL(hSession, PChar( URL), nil, 0, 0, 0);
try
Assign(f, OutputFile);
Rewrite(f, 1);
repeat
if PeekMessage(M, 0, 0, 0, pm_Remove) then
begin
TranslateMessage(M);
DispatchMessage(M);
end;
InternetReadFile(hURL, @Buffer, BufferSize, BufferLength);
BlockWrite(f, Buffer, BufferLength);
until BufferLength = 0;
Close(f);
Result := True; { if we get here, we succeeded }
finally
InternetCloseHandle(hURL);
end;
finally
InternetCloseHandle(hSession);
end;
end;
|
|
Zitat
|