- Регистрация
- 1 Мар 2015
- Сообщения
- 1,467
- Баллы
- 155
Код:
В Uses необходимо включить модуль: WinInet
Для определения размера файла воспользуемся следующей функцией:
function GetUrlSize(const URL:string):integer;
var
hSession,hFile:hInternet;
dwBuffer:array[1..20] of char;
dwBufferLen,dwIndex:DWORD;
begin
Result:=0;
hSession:=InternetOpen('GetUrlSize',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
if Assigned(hSession) then
begin
hFile:=InternetOpenURL(hSession,PChar(URL),nil,0,INTERNET_FLAG_RELOAD,0);
dwIndex:=0;
dwBufferLen:=20;
if HttpQueryInfo(hFile,HTTP_QUERY_CONTENT_LENGTH,@dwBuffer,dwBufferLen,dwIndex) then Result:=StrToInt(StrPas(@dwBuffer));
if Assigned(hFile) then InternetCloseHandle(hFile);
InternetCloseHandle(hsession);
end;
end;
Пример использования:
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
i:=GetUrlSize('http://www.delphicode.ru/delphi.png');
showmessage(inttostr(i));
end;