function TLisReport.DownloadFile(const remoteurl: string; Stream: TStream;
DownloadTitle: string): Boolean;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
BytesRead: DWORD;
Buffer: array[1..8192] of Char;
HaveRead: DWORD;
lpdwlen, lpdwidx, lpdword: DWord;
begin
Result := false;
NetHandle := InternetOpen(
'htmlcopy for Lis',
INTERNET_OPEN_TYPE_DIRECT,
nil,
nil,
0);
if Assigned(NetHandle) then begin
UrlHandle := InternetOpenUrl(
NetHandle,
PChar(remoteurl),
nil,
0,
INTERNET_FLAG_RELOAD,
0);
if Assigned(UrlHandle) then
begin
HaveRead := 0;
lpdword := 0;
lpdwlen := 4;
lpdwidx := 0;
HttpQueryInfo(UrlHandle, HTTP_QUERY_CONTENT_LENGTH or HTTP_QUERY_FLAG_NUMBER, @lpdword, lpdwlen, lpdwidx);
repeat
FillChar(Buffer, 8192, 0);
InternetReadFile(UrlHandle, @Buffer[1], SizeOf(Buffer), BytesRead);
Stream.Write(Buffer[1], bytesread);
HaveRead := HaveRead + bytesread;
hintProgress(DownloadTitle, round(HaveRead * 100 / lpdword));
until BytesRead = 0;
result := true;
hintProgress(DownloadTitle, 0);
end;
InternetCloseHandle(UrlHandle);
end;
InternetCloseHandle(NetHandle);
end;