home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / HISPEED2.LZH / NEWDOC / FILE.DOC < prev    next >
Text File  |  1991-04-06  |  5KB  |  150 lines

  1. New for version 1.1, Assign, SetTextBuf, changed syntax for Device.
  2.  
  3.  
  4. Changed chapters
  5.  
  6. Routines for Input and Output        PAGE 4.35.........
  7.  
  8. These are the routines that can be used for file I/O: 
  9.  
  10.   Assign, Reset, Rewrite, Append, Close, 
  11.   Seek, FilePos, FileSize, 
  12.   Eof, Eoln, SeekEof, SeekEoln, 
  13.   Read, Readln, Write, WriteLn, Page, BlockRead, BlockWrite, 
  14.   Rename, Erase, 
  15.   IOResult, SetTextBuf.
  16.  
  17. General control routines
  18. These are the routines used for creating, erasing, renaming and opening
  19. files: 
  20.  
  21.   Assign, Reset, Rewrite, Append, Close, Rename, Erase, IOResult.
  22.  
  23. Using Assign is the Turbo Pascal way of doing file I/O. Using Reset(F,Name)
  24. is the ST-Pascal way of doing things. The two ways of doing things can be
  25. mixed as long as a file title has been assigned to the file F using any of
  26. the calls that accepts Title as a parameter.
  27.  
  28. Assign (F, Title)
  29. Prepare the file F for use. Put the name Title into the name field of F. 
  30. If Assign is NOT used, the routines Reset, Rewrite and Append MUST supply
  31. a name in there calls. 
  32.  
  33. Reset (F)
  34. Open the file F for reading. If the file is already open it is first closed.
  35. The file must already have been given a name using Assign(F,Title)
  36. (or Reset(F,Title)). If the file is already open it is first closed. The
  37. file is read only if it is a text file. 
  38.  
  39. Reset (F, Title)
  40. Open the file named Title. Works like the sequence Assign(F,Title),
  41. Reset(F). 
  42. Rewrite(F)
  43. Open the file F for writing. If the file is already open it is first closed.
  44. The file must already have been given a name using Assign(F,Title). If the
  45. file named Title already exists, it is deleted. The file is write only if
  46. it is a text file.
  47.  
  48. Rewrite(F, Title)
  49. Open the file F for writing. Works like the sequence Assign(F,Title),
  50. Rewrite(F). 
  51.  
  52. Append(F)
  53. Only for textfiles. Open the file F for writing. The current file position
  54. is set to the end of the file. If the file is already open it is first
  55. closed. The file must already have been given a name using Assign(F,Title). 
  56.  
  57. Append(F, Title)
  58. Open the file F for writing. Works like the sequence Assign(F,Title),
  59. Append(F). 
  60.  
  61. Close(F)
  62. Flush unwritten data and close the file. 
  63.  
  64. Rename(OldName, NewName)
  65. Rename a file from OldName to NewName. Both parameters are string types. 
  66.  
  67. Erase(Title)
  68. Delete the file from the disk. 
  69.  
  70. IOResult: Integer
  71. Return the result of last input or output operation. Zero is returned when
  72. no errors has occurred. IOResult gets cleared by this call. 
  73.  
  74. SetTextBuf (F, Buffer)
  75. SetTextBuf (F, Buffer, Size)
  76. Assign an I/O buffer to a text file. The default buffer size is 128 bytes.
  77. If size is not specified, the whole Buffer is assumes as if SizeOf(Buffer)
  78. was written. SetTextBuf must be called right after Assign. It is also
  79. allowed to call it after Reset, Append and Rewrite before any I/O operations
  80. has occurred.
  81.  
  82. <<<<<<<<<<<<<<>'Typed and Untyped Files' following here............
  83.  
  84.  
  85.  
  86.  
  87.  
  88. Device Driver                               PAGE: A4-1
  89.  
  90. It is possible to define your own devices in HighSpeed Pascal. They are activated
  91. by Reset, Rewrite and Append calls when referenced by there logical name. 
  92.  
  93. A device is installed with a call to:
  94.  
  95.   Device(Name: String; IOprocedure: Pointer; DevBuf: TDevBuf).
  96.  
  97. The call Device('MyDriver',@MyDriver,DevBuf) installs the name along with
  98. the address of the IO handler in the private buffer DevBuf. Do not use
  99. DevBuf after giving it to Device.
  100.  
  101. The DevBuf is declared as:
  102.  
  103. VAR DevBuf: TDevBuf; {Buffer for Device to work in}
  104.  
  105. The IOprocedure must have a heading like this:
  106.  
  107.   Function MyDriver(var F: TextRec): Integer;
  108.  
  109. By looking at the flags the routine can see why it is called. The function
  110. value returned is put into the IOResult variable, forcing a runtime error
  111. if $I+ is used.
  112.  
  113. The routine gets called by Write, Writeln, Page, Read, Readln, Close, Eof,
  114. SeekEof, Eoln and SeekEoln whenever input or output must be performed. 
  115.  
  116. fInpFlag is set when the driver should read fBufSize bytes (characters)
  117. into the buffer fBuffer^. fBufPos is then set to zero, and fBufEnd is set
  118. to show how many bytes actually got read. Whenever zero byte is read, Eof
  119. is true. 
  120.  
  121. fOutFlag is set when the driver should write fBufPos bytes from the buffer
  122. fBuffer^. fBufPos is set to zero if the data is written. It is legal not
  123. to do anything if the buffer is not full, that is if fBufPos does not equal
  124. fBufEnd. 
  125.  
  126. A skeleton driver:
  127.  
  128. Function MyDriver(var F: TextRec): Integer;
  129. var
  130.   P:  Integer;
  131.   Ch: char;
  132. begin
  133.   MyDriver:=0; {IOResult:=Ok}
  134.   With F do begin
  135.     if fInpFlag then begin
  136.       fBufEnd:=0;
  137.       repeat
  138.         Ch:=ReadKey;
  139.         fBuffer^[fBufEnd]:=Ch; Inc(fBufEnd);
  140.       until (Ch=#10) or (Ch=^Z) or (fBufEnd=fBufSize);
  141.     end else {Doing output}
  142.       {if fBufPos<>fBufEnd then {Always or when full}
  143.       begin
  144.         for P:=0 to fBufPos-1 do WriteCh(fBuffer^[P]);
  145.         fBufPos:=0;
  146.       end;
  147.   end;
  148. end;
  149.  
  150.