Reading binary files in PASCAL ?? 
Author Message
 Reading binary files in PASCAL ??

Does anyone outthere know how to read binary-files with Pascal ???

Thanks in advance,

COEN DONDERS



Wed, 18 Jun 1902 08:00:00 GMT  
 Reading binary files in PASCAL ??

Quote:
> Does anyone outthere know how to read binary-files with PASCAL ???

   Sure, but you'll have to be more specific about what type of file(s)
you're trying to read.  There are 2 ways to read "binary" files in TP/BP:
typed file i/o (Reset, Seek/Read) and untyped (Reset, BlockRead).  The
data brought into the program by each type is very different, and each
requires very different processing.
   If you can describe the information in the "binary" file in Pascal
terms, then most likely you can define a record type and a file of that
type - which is typed file i/o.  If it's just a bunch of bytes/characters
with no pattern (such as a .ZIP file), then it's probably best handled
with untyped file i/o.
   As I said, the two types of "binary" file i/o are completely
different, and you'll have to explain what the data on the file is,
before we can give you more help.


Wed, 18 Jun 1902 08:00:00 GMT  
 Reading binary files in PASCAL ??


Quote:
> Does anyone outthere know how to read binary-files with PASCAL ???

> Thanks in advance,

> COEN DONDERS

Yep, I know how to.

Var
  F : File Of Byte ;
  B : Byte ;

Begin
  Assign (F, 'FileName') ;
  Reset (F) ;
  While Not Eof (F) Do
    Begin
      Read (F, B) ;
      ...
    End ;
  Close (F)
End ;

You can allso use BlockRead.

ASS-Ware



Wed, 18 Jun 1902 08:00:00 GMT  
 Reading binary files in PASCAL ??

Quote:

>Does anyone outthere know how to read binary-files with PASCAL ???
>Thanks in advance,
>COEN DONDERS

Typed files ot BlockRead/Write on untyped ones

Cheers
  Dmitri

--------------------------------------------------------------
        Shit happens, but why it always happens to us?
--------------------------------------------------------------

                            http://www.dma.be/p/bewoner/dmitri



Wed, 18 Jun 1902 08:00:00 GMT  
 Reading binary files in PASCAL ??

Quote:


>>Does anyone outthere know how to read binary-files with PASCAL ???
>>Thanks in advance,
>>COEN DONDERS
>Typed files ot BlockRead/Write on untyped ones
>Cheers
>  Dmitri
>--------------------------------------------------------------
>        Shit happens, but why it always happens to us?
>--------------------------------------------------------------

>                            http://www.dma.be/p/bewoner/dmitri

What kind of binary files do you mean ?

It all depends on the information of the file !!

Ludo De Meyer



Wed, 18 Jun 1902 08:00:00 GMT  
 Reading binary files in PASCAL ??

Quote:

> Does anyone outthere know how to read binary-files with PASCAL ???

> Thanks in advance,

> COEN DONDERS

Just write :
Var f : file of byte/word;
    b : byte/word;
    i : longint;
begin
.
.
.
        assign(f,'...');
        reset(f);
        for i := 1 to filesize(f) do
                read(f,b);
        close(f);
end.
     Leonid Igolnik.
Bar Rav Hai David st. 44 / 5
Haifa                  35591
Israel



Wed, 18 Jun 1902 08:00:00 GMT  
 Reading binary files in PASCAL ??

: Does anyone outthere know how to read binary-files with PASCAL ???
:
: Thanks in advance,
:
: COEN DONDERS
:

Something like:
----------------------------
TYPE
   tHeader = RECORD
      width : INTEGER;
      height : INTEGER;
      palentries : INTEGER;
   END;

   tPalEntry = RECORD
      r, g, b : BYTE;
   END;

   tPic = ARRAY [0..2047] OF POINTER;

VAR
   f : FILE;
   h : tHeader;
   p : ARRAY [0..255] OF tPalEntry;
   d : tPic;
   i, j : INTEGER;
BEGIN
   Assign (f, Filename);
   Reset (f, 1);
   BlockRead (f, h, Sizeof (tHeader));
   IF h.palentries > 256 THEN Error ('Can''t handle large pals');
   { I assume that Error will call exit (or halt ?) }
   BlockRead (f, p, h.palentries * Sizeof (tPalEntry));
   IF h.height > 2048 THEN Error ('That's to big!');
   FOR i := 0 TO h.height-1 DO
   BEGIN
      GetMem (d [i], h.width);
      BlockRead (f, d [i]^, h.width);
   END;
   Close (f);
END;

--

     CU Peter

     -------------------------------------------------------------------

     There was a point to this story, but it has temporarily escaped the
     chronicler's mind.
                   Douglas Adams, "So Long, and Thanks for all the Fish"



Wed, 18 Jun 1902 08:00:00 GMT  
 Reading binary files in PASCAL ??

Quote:


>>Does anyone outthere know how to read binary-files with PASCAL ???
>>Thanks in advance,
>>COEN DONDERS
>Typed files ot BlockRead/Write on untyped ones
>Cheers
>  Dmitri
>--------------------------------------------------------------
>        Shit happens, but why it always happens to us?
>--------------------------------------------------------------

>                            http://www.dma.be/p/bewoner/dmitri

What kind of binary files do you mean ?

It all depends on the information of the file !!

Ludo De Meyer



Wed, 18 Jun 1902 08:00:00 GMT  
 Reading binary files in PASCAL ??

Quote:



> > >Does anyone outthere know how to read binary-files with PASCAL ???
> >Typed files ot BlockRead/Write on untyped ones
> What kind of binary files do you mean ?
> It all depends on the information of the file !!

Search for the help on Blockread or Blockwrite. There should be a good
example program there somewhere (at least if you're using TP7/BP7


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Reading binary files in pascal

2. Can Excel read a Pascal binary file?

3. Converting binary (text file) to compress binary file

4. problems reading binary file, and outputting to screen.

5. reading binary file and outputting to standard output (screen)

6. I need to read a binary file

7. problem reading 4-byte reals from binary file

8. Reading Pascal-generated PACKED binary w/ C program

9. Making binary files in pascal for an OS

10. file2inc.zip Binary data to INC file maker for Turbo Pascal

11. Converting Turbo Pascal binary data files with C++

12. Binary -font file for Pascal

 

 
Powered by phpBB® Forum Software