Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo Pascal - <b> file declare untyped file pp 114</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 FILE                        Declare Untyped File                     pp 114


 Define:  A file declared without a type using the reserved word file.

 Purpose: Provides fast unformatted access to disk files in blocks of 128
          bytes.

 Notes:   With untyped files, read and write operations to disk files are
          transferred directly between the file and the variable, saving
          the disk buffer space required by typed files.  Untyped files
          are compatible with all file types.


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


 Usage:
       CONST
          BufSize  : Integer = $1FF      ; { $1FF blocks = 65408 bytes      }
       TYPE
          BfrPtr   = ^Byte               ; { Buffer pointer is type Byte    }
       VAR
          Buffer   : BfrPtr              ; { Buffer pointer                 }
          FileVar  : File                ; { Untyped file                   }
          Result   : Integer             ; { Number of 128 byte blocks read }

       BEGIN
          GetMem (Buffer,$FFFF)          ; { Get $FFFF heap space for buffr }
          Assign (FileVar,'D:TestData.') ; { Assign filename to handle      }
          Reset  (FileVar)               ; { Open handle for read           }
          Repeat                           { Load buffer until EOF          }
            BlockRead (FileVar,Buffer^,BufSize,Result);
          Until Result = 0               ; { Read file until no more left   }
          Close  (FileVar)               ; { Close the file handle          }
       END.

See Also: BlockRead BlockWrite File Of Files

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson