function DownloadURL(
const aUrl:
string; bildart:
string): Boolean;
var
hSession: HINTERNET;
hService: HINTERNET;
lpBuffer:
array[0..1024 + 1]
of Char;
dwBytesRead: DWORD;
aStream : TFileStream;
begin
Result := False;
hSession := InternetOpen('
MyApp', INTERNET_OPEN_TYPE_PRECONFIG,
nil,
nil, 0);
try
if Assigned(hSession)
then begin
hService := InternetOpenUrl(hSession, PChar(aUrl),
nil, 0, 0, 0);
if Assigned(hService)
then
try
aStream := TFileStream.Create('
temp_bild'+ ExtractFileExt(aURL), fmCreate);
while True
do begin
dwBytesRead := 1024;
InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);
if dwBytesRead = 0
then break;
lpBuffer[dwBytesRead] := #0;
aStream.WriteBuffer(lpBuffer, dwBytesRead);
end;
aStream.Position := 0;
// JPG
if bildart = '
jpg'
then begin
try
Form2.Image1.Visible := true;
form2.image1.Picture.Graphic.LoadFromStream(aStream);
except
// showmessage('fehler'); // jpeg-Fehler #52
on E:
Exception do showmessage('
Fehler beim Laden des Artikelbildes');
end;
end;
// Gif
if bildart = '
gif'
then begin
Form2.Image2.Visible := true;
form2.image2.Picture.Graphic.LoadFromStream(aStream);
end;
Result := True;
finally
FreeAndNil(aStream);
InternetCloseHandle(hService);
end;
end;
finally
InternetCloseHandle(hSession);
end;
end;