Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Internet
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 03-07-2007
fmatias fmatias is offline
Miembro
 
Registrado: jun 2003
Posts: 25
Poder: 0
fmatias Va por buen camino
Descargar fichero 25 Mb desde internet

Hola a todos,
Quiero crear una aplicación que descargue un fichero desde internet similar a la descarga desde cualquier navegador. Con la siguiente función que os indico realiza el proceso, pero va muy lento y se queda colgado cuando lleva un 10% aprox.
Respecto a la velocidad, he realizado varias pruebas desde distintos navegadores y todos van hasta 10 veces más rápido.

Podríais ayudarme a depurarlo mejor?
Código Delphi [-]
function TForm1.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;
Muchas gracias
F.Matías.
Responder Con Cita
 



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

Temas Similares
Tema Autor Foro Respuestas Último mensaje
descargar archivo desde php gulder PHP 2 07-06-2007 08:28:26
Descargar tabla a fichero plano isg SQL 1 27-10-2006 21:47:57
cargar desde fichero? jam888 Varios 3 10-02-2006 15:01:24
Descargar imágenes de internet via http. alfredosg19 Internet 2 08-04-2005 13:02:27
Descargar y ejecutar aplicacion desde el navegador coulthard Linux 0 23-12-2004 18:40:08


La franja horaria es GMT +2. Ahora son las 08:02:59.


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