Blockread / Blockwrite 
Author Message
 Blockread / Blockwrite

Quote:
> I need help to know how and where to use the blockread and blockwrite
> procedures.

   A rather strange request, given that you don't know how to do it - did
someone tell you you _had_ to use Block* for something, or do you think
it's and solution to a problem you have?  If it's the former, then
there's no real value in learning about something which may/may not work
for you; if it's the latter, you should have explained your problem, so
we could help you solve it - it might not be a good application for the
Block* procedures.
   The Block* procedures perform read and write to untyped files - files
which aren't Text or "file of record_type".  These are files which are
just declared as "file".  Such files have no structure, but are just a
large number of bytes/characters (you may treat them as either, depending
on how you declare the buffer you read such files into).  Untyped files
are essentially anything which can't be declared as a Pascal data/file
type, and it's up to the programmer to process a number of the
bytes/characters in some fashion which makes sense to the application.  
Therefore, I can't tell you "how to use the data" for such files - it's
just a buffer of undefined characters or bytes.
   To open such a file, you declare the file as "file_var : file;",
Assign it, and Reset/Rewrite it, according to whether you're going to
read or write to it (you can read _and_ write an existing file, with
reset, but that's more information than I can explain here...).  Then,
you either BlockRead or BlockWrite to/from a declared buffer - 4K bytes
is a good size for many uses.  The BlockRead 4th parameter allows you to
know how many characters/bytes were read into the buffer, so you'll know
when the EOF is reached.
   I suggest you look in the TP/BP manuals, under the Block* procedures,
to see how and why these procedures are actually used.  Giving a generic
description such as this, has little meaning, IMHO, since you really need
a reason for using such procedures - like everything else in any
programming language.  The examples provided will do the most good, I
believe...


Wed, 18 Jun 1902 08:00:00 GMT  
 Blockread / Blockwrite

I need help to know how and where to use the blockread and blockwrite
procedures.

I apreciate.




Wed, 18 Jun 1902 08:00:00 GMT  
 Blockread / Blockwrite


Quote:
>I need help to know how and where to use the blockread and blockwrite
>procedures.

1) When.... using untyped binary files....

2) How....

blockread(<fileid>,<var>,<sizeof var>, <how much read>)

blockwrite(<fileid>,<var>,<how much read>,<how much written>)

Usage:

For example, we write a copy program.  Snippet of it would be,
assuming a read-in buffer of array[1..4096] of byte;

program x;
  var
     infile, outfile: file;
     buffer: { as above};
     numread, numwritten: integer;

  begin
     { logic to get files}
     reset(infile, 1);   { the ,1 is needed...tells it a blocking
factor -- no need to use anything other than 1, really}
     { opening write file }
     repeat
        blockread(infile, buffer, sizeof(buffer), numread);
        blockwrite(outfile, buffer, numread, numwritten);
     until numread = 0;
  end.

numread and numwritten are not required, but illustrated for this
context.



Wed, 18 Jun 1902 08:00:00 GMT  
 Blockread / Blockwrite


: I need help to know how and where to use the blockread and blockwrite
: procedures.
:
: I apreciate.

You'd use them whenever you've got to deal with files with various size/type
data blocks, e.g. images

Let's assume we've got a very basic raw image using the specs (There's
actually no such format):

256 Colors, No Compression,

BYTE            Content
0000-0001       magic word
0002-0003       width
0004-0006       height
0008-000F       reserved
0010-0309       palette info
0310-????       pixel data

Now the Code:
-------------------------------------------------------------------------
PROCEDURE ReadRaw (aFN : PathString);
TYPE
   tHeader = RECORD
      magic : WORD;
      width : WORD;
      height : WORD;
      reserved : WORD;  {To read it together with the rest of the header}
   END;

   tPalette = ARRAY [0..255,0..2] OF BYTE;

   pPointerArr = ^tPointerArr;
   tPointerArr = ARRAY [0..15000] OF POINTER;
VAR
   f : FILE;
   header : tHeader;
   palette : tPalette;
   frame : pPointerArr;
BEGIN
   Assign (f, aFN);
   Reset (f, 1); {Tell him, you want 1-Byte Blocks}
   BlockRead (f, header, SizeOf (tHeader));
   BlockRead (f, palette, SizeOf (tPalette));
   GetMem (frame, SizeOf (Pointer) * header.height);
   FOR i := 0 TO header.height-1 DO
   BEGIN
      GetMem (frame^[i], width);
      BlockRead (f, frame^[i]^, width);
   END;
   Close (f);
END;
------------------------------------------------------------------------
This should do the Job!

--

     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  
 Blockread / Blockwrite



:I need help to know how and where to use the blockread and blockwrite

 105100 Sep 14 1996 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

"If you do not know how to go about getting this material, users are
welcome to email me for the prerecorded garbo.uwasa.fi instructions
(long, about 29Kb). If you do not receive my reply within five days,
please ask your own site's system manager to construct a returnable
mail path for you".

   All the best, Timo

....................................................................

Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa



Wed, 18 Jun 1902 08:00:00 GMT  
 Blockread / Blockwrite

I need help to know how and where to use the blockread and blockwrite
procedures.

I apreciate.




Wed, 18 Jun 1902 08:00:00 GMT  
 Blockread / Blockwrite



:I need help to know how and where to use the blockread and blockwrite
:procedures.

 105100 Sep 14 1996 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

In particular see items
 62) How can I copy a file in a Turbo Pascal program?
 23) What is all this talk about "Pascal homework on the net"?

   All the best, Timo

....................................................................

Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa



Wed, 18 Jun 1902 08:00:00 GMT  
 Blockread / Blockwrite

Quote:
> I need help to know how and where to use the blockread and blockwrite
> procedures.

   Where: untyped files.  How: look up both in the manuals and/or online
Help.


Wed, 18 Jun 1902 08:00:00 GMT  
 Blockread / Blockwrite

Reposting article removed by rogue canceller.



:I need help to know how and where to use the blockread and blockwrite
:procedures.

 105100 Sep 14 1996 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers

In particular see items
 62) How can I copy a file in a Turbo Pascal program?
 23) What is all this talk about "Pascal homework on the net"?

   All the best, Timo

....................................................................

Moderating at ftp:// & http://garbo.uwasa.fi archives  193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa



Wed, 18 Jun 1902 08:00:00 GMT  
 Blockread / Blockwrite

Reposting article removed by rogue canceller.

I need help to know how and where to use the blockread and blockwrite
procedures.

I apreciate.




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

 Relevant Pages 

1. Blockread/Blockwrite question.

2. Blockread/Blockwrite question

3. Urgent help needed with GFx mode and BlockRead/BlockWrite

4. blockread/blockwrite

5. How do I use BLOCKREAD/BLOCKWRITE

6. BLOCKREAD&BLOCKWRITE?

7. Problems using seek and blockwrite

8. Blockwrite

9. blockwrite anomaly?

10. BlockWrite

11. BlockWrite problem.

12. Blockwrite constant

 

 
Powered by phpBB® Forum Software