Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.10.30;
Скачать: CL | DM;

Вниз

Как получить информацию из файла с инета   Найти похожие ветки 

 
Виталий09   (2005-10-08 17:40) [0]

Здравствуйте!

Уважаемые мастера, подскажите пожалуйста как можно (на программном уровне) скачать
текстовый фаил с моего интернета-сайта и открыть его в memo

Заранее, спасибо.


 
Zeqfreed ©   (2005-10-08 19:51) [1]

Виталий09   (08.10.05 17:40)
Простейший вариант:


uses WinInet;

function InetGetPage(const Agent, Server, Path : String) : String;
var
hInet, hConnect, hReq : hInternet;
buf : array[1..1024] of Char;
read : Cardinal;
ReadFlag, ReqSent : boolean;

err : boolean;
errcode : Integer;
begin
err := false;

hInet := InternetOpen(PChar(Agent), INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);
if hInet <> nil then begin
 hConnect := InternetConnect(hInet, PChar(Server), INTERNET_DEFAULT_HTTP_PORT, nil, nil, INTERNET_SERVICE_HTTP, 0, 0);
 if hConnect <> nil then begin
   hReq := HttpOpenRequest(hConnect, "GET", PChar(Path), HTTP_VERSION, nil, 0, 0, 0);
   if hReq <> nil then begin
    ReqSent := HttpSendRequest(hReq, nil, 0, nil, 0);
    if ReqSent then begin
     repeat
      ReadFlag := InternetReadFile(hReq, @buf, SizeOf(buf), read);
      Result := Result + Copy(buf, 1, read);
     until (not ReadFlag) or (read = 0);
    end else begin
     err := true;
     errcode := GetLastError();
   end;
  end else begin
   err := true;
   errcode := GetLastError();
  end;
 end else begin
  err := true;
  errcode := GetLastError();
 end;
end else begin
 err := true;
 errcode := GetLastError();
end;

if err then begin
 MessageBox(0, PChar("Error #" + IntToStr(errcode) + " has been occured"), "Connection failed", MB_OK or MB_ICONWARNING);
end;

InternetCloseHandle(hReq);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInet);
end;


Пример использования:
Memo1.Text := InetGetPage("123", "www.delphimaster.ru", "http://delphimaster.net/view/2-1128778852/");



Страницы: 1 вся ветка

Текущий архив: 2005.10.30;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.05 c
3-1127105558
Muchacho
2005-09-19 08:52
2005.10.30
BDE без InstallShield


3-1127212198
mrAld
2005-09-20 14:29
2005.10.30
Модификация полей в наборе данных ADO


2-1128532929
747
2005-10-05 21:22
2005.10.30
Текстовый квест - нужна помощь.


2-1128945580
SPACE
2005-10-10 15:59
2005.10.30
Народ никак немогу сделать скриншот из игрушки


3-1127195082
rayrom
2005-09-20 09:44
2005.10.30
Как обойти проблему связи таблиц!