Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Descargar con ProgressBar (https://www.clubdelphi.com/foros/showthread.php?t=59839)

MAXIUM 10-09-2008 17:53:13

Descargar con ProgressBar
 
Quisiera saber como le meto un progressbar o en su defecto saber el tamaño del archivo antes de descargar. Gracias :)

Usando solo WinINet
Código Delphi [-]
function DescargarArchivo( sURL, sArchivoLocal: String ): boolean;
const BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of Byte;
  LongitudBuffer: DWORD;
  F: File;
  sMiPrograma: String;
begin
  sMiPrograma := ExtractFileName( Application.ExeName );
  hSession := InternetOpen( PChar( sMiPrograma ), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0 );

  try
    hURL := InternetOpenURL( hSession, PChar( sURL ), nil, 0, 0, 0 );

    try
      AssignFile( F, sArchivoLocal );
      Rewrite( F, 1 );

      repeat
        InternetReadFile( hURL, @Buffer, SizeOf( Buffer ), LongitudBuffer );
        BlockWrite( F, Buffer, LongitudBuffer );
      until LongitudBuffer = 0;

      CloseFile( F );
      Result := True;
    finally
      InternetCloseHandle( hURL );
    end
  finally
    InternetCloseHandle( hSession );
  end
end;

Parametro
Código Delphi [-]
DescargarArchivo( 'http:\\miweb.com\imagen.jpg', 'C:\Mis documentos\imagen.jpg' );


http://delphiallimite.blogspot.com/2...ernet-sin.html

dec 10-09-2008 18:04:15

Hola,

Podrías leer los artículos que sobre el API WinInet se encuentran en la Web de JM. ;)

MAXIUM 10-09-2008 19:00:50

Muchisimas gracias DEC, ya encontre la solución donde dijiste ;)


La franja horaria es GMT +2. Ahora son las 07:17:16.

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