[fpc-pascal]Problems with FileIO

Anton Tichawa anton.tichawa at chello.at
Wed Nov 6 11:04:09 CET 2002


Hi, Eduardo!

The blockread function has the declaration:

Procedure Blockread (Var F : File; Var Buffer; Var Count : Longint [; var 
Result : Longint]); 

If the "Result" parameter is not specified, as is the case in your program, 
an error is generated when there are less than Count bytes available in the 
input file.

With the "Result" parameter, no error is generated, and "Result" returns the
number of bytes actually read from the file.

Try to change your code to:

      bla bla
      var
          BytesRead: Longint;
      Repeat
            BytesLeidos := 64;
            blockread(FileIn,Entrada^,BytesLeidos, BytesRead);
            if BytesRead > 0 then begin
                  bla bla
HTH.

Anton.

 
On Wednesday 06 November 2002 00:46, Eduardo Morras wrote:
> Hello everyone:
>
>          I'm new to fpc and i'm trying to port some mac pascal code to
> win32 console. I have this code to read 64 bytes of data from a file, work
> with them and save a double and 64 bytes of data. Of course if blockread
> reads f.e. 32 bytes it saves the double and 32 bytes. But when i want to
> check the output file size is different from the expected. So i have an
> input file of 4369 bytes, with 68 blocks of 64 bytes plus a block of 17
> bytes (4369-64*68), the output file size must be 68 * 8 + 68 * 64 + 1 * 8 +
> 1 * 17 = 4921 bytes. But i get 4896, which are 25 bytes less (25 bytes =
> 8(from double)+17(the last block size)). So, the program don't treat the
> last data block. The debugger says error 100 (FileIO problem), but what can
> i do make it work for?
>
>
>      cuant : Pointer to array[0..63] of byte;
>
>      Repeat
>            BytesLeidos := 64;
>            blockread(FileIn,Entrada^,BytesLeidos);
>            if BytesLeidos>0 then begin
>               AjustarBloque(BytesLeidos-1);                     //Substrac
> 1 for 0-based array bounds
>               CuantificarBloque(BytesLeidos-1);                //Substrac 1
> for 0-based array bounds
>               blockwrite(FileOut,factor,sizeof(double));
>               blockwrite(FileOut,cuant^,BytesLeidos*sizeof(byte));
>            end;
>      Until (EOF(FileIn)) OR (BytesLeidos=0);
>
> TIA
>
> La diferencia entre la teoria y la practica es que en teoria no hay, pero
> en la practica si
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list