Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Los mejores trucos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-06-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 24
seoane Va por buen camino
Bajar archivo con Wininet

Código Delphi [-]
uses Wininet;

function Bajar(Url: string; Archivo: string): Boolean;
var
  hFile: THandle;
  hNet: HINTERNET;
  hUrl: HINTERNET;
  Buffer: array[0..10240] of Char;
  BytesRead: DWORD;
  BytesWritten: DWORD;
begin
  Result := FALSE;
  hFile := CreateFile(PChar(Archivo), GENERIC_WRITE, 0, nil, CREATE_ALWAYS,
    FILE_ATTRIBUTE_NORMAL, 0);
  if (hFile <> INVALID_HANDLE_VALUE) then
  begin
    hNet := InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
    if (hNet <> nil) then
    begin
      hUrl := InternetOpenUrl(hNet, PChar(Url), nil, 0,
        INTERNET_FLAG_RELOAD, 0);
      if (hUrl <> nil) then
      begin
        while (InternetReadFile(hUrl, @Buffer, sizeof(Buffer), BytesRead)) do
        begin
          // Añadir la siguiente liena si es necesario
          // Application.ProcessMessages;
          if (BytesRead = 0) then
          begin
            Result := TRUE;
            break;
          end;
          if (not WriteFile(hFile, Buffer, BytesRead, BytesWritten, nil)) then
            break;
          if (BytesRead <> BytesWritten) then
            break;
        end;
        InternetCloseHandle(hUrl);
      end;
      InternetCloseHandle(hNet);
    end;
    CloseHandle(hFile);
  end;
end;

Ejemplo de uso:
Código Delphi [-]
  Bajar('http://www.google.com/intl/es_ALL/images/logo.gif','d:\google.gif');
  Bajar('ftp://ftp.opera.com/pub/opera/win/lng/754/es-ES/ow754_3865es-ES.lng','d:\1.lng');
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 01:44:53.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi