Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Problema a descargar actualización mediante WinInet (https://www.clubdelphi.com/foros/showthread.php?t=82799)

wolfran_hack 15-04-2013 13:00:35

Problema a descargar actualización mediante WinInet
 
CODE:

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 ); //ERROR AQUI.
      until LongitudBuffer = 0;

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

Código Delphi [-]
procedure Form1.Button1Click(Sender: TObject);
begin
  DescargarArchivo( 'http:\\site.com\dni.csv', 'C:\dni.csv' );
end;

El archivo pesa 20Kb y me tirar error en el Buffer señalando esa linea y el texto:

Cita:

Project DNI.exe raised exception class EInOutError with message 'I/O error 1784'. Process stopped. Use Step or Run to continue.
Alguna idea?

olbeup 15-04-2013 13:54:43

Hola wolfran_hack

Creo que la línea ésta está mal:
Código Delphi [-]
InternetOpen( PChar( sMiPrograma ), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0 );
Usa este otro:
Código Delphi [-]
InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0 );

Un saludo


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

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