home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Vectronix 2
/
VECTRONIX2.iso
/
FILES_01
/
HISPEED2.LZH
/
NEWDOC
/
FILE.DOC
< prev
next >
Wrap
Text File
|
1991-04-06
|
5KB
|
150 lines
New for version 1.1, Assign, SetTextBuf, changed syntax for Device.
Changed chapters
Routines for Input and Output PAGE 4.35.........
These are the routines that can be used for file I/O:
Assign, Reset, Rewrite, Append, Close,
Seek, FilePos, FileSize,
Eof, Eoln, SeekEof, SeekEoln,
Read, Readln, Write, WriteLn, Page, BlockRead, BlockWrite,
Rename, Erase,
IOResult, SetTextBuf.
General control routines
These are the routines used for creating, erasing, renaming and opening
files:
Assign, Reset, Rewrite, Append, Close, Rename, Erase, IOResult.
Using Assign is the Turbo Pascal way of doing file I/O. Using Reset(F,Name)
is the ST-Pascal way of doing things. The two ways of doing things can be
mixed as long as a file title has been assigned to the file F using any of
the calls that accepts Title as a parameter.
Assign (F, Title)
Prepare the file F for use. Put the name Title into the name field of F.
If Assign is NOT used, the routines Reset, Rewrite and Append MUST supply
a name in there calls.
Reset (F)
Open the file F for reading. If the file is already open it is first closed.
The file must already have been given a name using Assign(F,Title)
(or Reset(F,Title)). If the file is already open it is first closed. The
file is read only if it is a text file.
Reset (F, Title)
Open the file named Title. Works like the sequence Assign(F,Title),
Reset(F).
Rewrite(F)
Open the file F for writing. If the file is already open it is first closed.
The file must already have been given a name using Assign(F,Title). If the
file named Title already exists, it is deleted. The file is write only if
it is a text file.
Rewrite(F, Title)
Open the file F for writing. Works like the sequence Assign(F,Title),
Rewrite(F).
Append(F)
Only for textfiles. Open the file F for writing. The current file position
is set to the end of the file. If the file is already open it is first
closed. The file must already have been given a name using Assign(F,Title).
Append(F, Title)
Open the file F for writing. Works like the sequence Assign(F,Title),
Append(F).
Close(F)
Flush unwritten data and close the file.
Rename(OldName, NewName)
Rename a file from OldName to NewName. Both parameters are string types.
Erase(Title)
Delete the file from the disk.
IOResult: Integer
Return the result of last input or output operation. Zero is returned when
no errors has occurred. IOResult gets cleared by this call.
SetTextBuf (F, Buffer)
SetTextBuf (F, Buffer, Size)
Assign an I/O buffer to a text file. The default buffer size is 128 bytes.
If size is not specified, the whole Buffer is assumes as if SizeOf(Buffer)
was written. SetTextBuf must be called right after Assign. It is also
allowed to call it after Reset, Append and Rewrite before any I/O operations
has occurred.
<<<<<<<<<<<<<<>'Typed and Untyped Files' following here............
Device Driver PAGE: A4-1
It is possible to define your own devices in HighSpeed Pascal. They are activated
by Reset, Rewrite and Append calls when referenced by there logical name.
A device is installed with a call to:
Device(Name: String; IOprocedure: Pointer; DevBuf: TDevBuf).
The call Device('MyDriver',@MyDriver,DevBuf) installs the name along with
the address of the IO handler in the private buffer DevBuf. Do not use
DevBuf after giving it to Device.
The DevBuf is declared as:
VAR DevBuf: TDevBuf; {Buffer for Device to work in}
The IOprocedure must have a heading like this:
Function MyDriver(var F: TextRec): Integer;
By looking at the flags the routine can see why it is called. The function
value returned is put into the IOResult variable, forcing a runtime error
if $I+ is used.
The routine gets called by Write, Writeln, Page, Read, Readln, Close, Eof,
SeekEof, Eoln and SeekEoln whenever input or output must be performed.
fInpFlag is set when the driver should read fBufSize bytes (characters)
into the buffer fBuffer^. fBufPos is then set to zero, and fBufEnd is set
to show how many bytes actually got read. Whenever zero byte is read, Eof
is true.
fOutFlag is set when the driver should write fBufPos bytes from the buffer
fBuffer^. fBufPos is set to zero if the data is written. It is legal not
to do anything if the buffer is not full, that is if fBufPos does not equal
fBufEnd.
A skeleton driver:
Function MyDriver(var F: TextRec): Integer;
var
P: Integer;
Ch: char;
begin
MyDriver:=0; {IOResult:=Ok}
With F do begin
if fInpFlag then begin
fBufEnd:=0;
repeat
Ch:=ReadKey;
fBuffer^[fBufEnd]:=Ch; Inc(fBufEnd);
until (Ch=#10) or (Ch=^Z) or (fBufEnd=fBufSize);
end else {Doing output}
{if fBufPos<>fBufEnd then {Always or when full}
begin
for P:=0 to fBufPos-1 do WriteCh(fBuffer^[P]);
fBufPos:=0;
end;
end;
end;