TDosStream is a stream that stores it’s contents in a file. it overrides a couple of methods of
TSteam for this.
In addition to the fields inherited from TStream (see section 17.6, page 565), there are some extra
fields, that describe the file. (mainly the name and the OS file handle)
No buffering in memory is done when using TDosStream. All data are written directly to the file.
For a stream that buffers in memory, see section 17.8, page 582.
Here is the full declaration of the TDosStream object:
TYPE
TDosStream = OBJECT (TStream)
Handle: THandle; { DOS file handle }
FName : AsciiZ; { AsciiZ filename }
CONSTRUCTOR Init (FileName: FNameStr; Mode: Word);
DESTRUCTOR Done; Virtual;
PROCEDURE Close; Virtual;
PROCEDURE Truncate; Virtual;
PROCEDURE Seek (Pos: LongInt); Virtual;
PROCEDURE Open (OpenMode: Word); Virtual;
PROCEDURE Read (Var Buf; Count: Sw_Word); Virtual;
PROCEDURE Write (Var Buf; Count: Sw_Word); Virtual;
END;
PDosStream = ^TDosStream;
|
-
Declaration:
- Constructor Init (FileName: FNameStr; Mode: Word);
-
Description:
- Init instantiates an instance of TDosStream. The name of the file that contains (or will contain)
the data of the stream is given in FileName. The Mode parameter determines whether a new file
should be created and what access rights you have on the file. It can be one of the following
constants:
-
stCreate
- Creates a new file.
-
stOpenRead
- Read access only.
-
stOpenWrite
- Write access only.
-
stOpen
- Read and write access.
-
Errors:
- On error, Status is set to stInitError, and ErrorInfo is set to the DOS error code.
-
See also:
- Done (577)
For an example, see TDosStream.Truncate (578).
-
Declaration:
- Destructor TDosStream.Done; Virtual;
-
Description:
- Done closes the file if it was open and cleans up the instance of TDosStream.
-
Errors:
- None.
-
See also:
- Init (577), Close (578)
for an example, see e.g. TDosStream.Truncate (578).
-
Declaration:
- Pocedure TDosStream.Close; Virtual;
-
Description:
- Close closes the file if it was open, and sets Handle to -1. Contrary to Done (577) it does
not clean up the instance of TDosStream
-
Errors:
- None.
-
See also:
- TStream.Close (570), Init (577), Done (577)
For an example, see TDosStream.Open (580).
-
Declaration:
- Procedure TDosStream.Truncate; Virtual;
-
Description:
- If the status of the stream is stOK, then Truncate tries to truncate the stream size to the
current file position.
-
Errors:
- If an error occurs, the stream’s status is set to stError and ErrorInfo is set to the OS
error code.
-
See also:
- TStream.Truncate (571), GetSize (568)
Listing: objectex/ex16.pp
-
Declaration:
- Procedure TDosStream.Seek (Pos: LongInt); Virtual;
-
Description:
- If the stream’s status is stOK, then Seek sets the file position to Pos. Pos is a zero-based
offset, counted from the beginning of the file.
-
Errors:
- In case an error occurs, the stream’s status is set to stSeekError, and the OS error code is
stored in ErrorInfo.
-
See also:
- TStream.Seek (572), GetPos (568)
Listing: objectex/ex17.pp
-
Declaration:
- Procedure TDosStream.Open (OpenMode: Word); Virtual;
-
Description:
- If the stream’s status is stOK, and the stream is closed then Open re-opens the file stream
with mode OpenMode. This call can be used after a Close (578) call.
-
Errors:
- If an error occurs when re-opening the file, then Status is set to stOpenError, and the OS
error code is stored in ErrorInfo
-
See also:
- TStream.Open (570), Close (578)
Listing: objectex/ex14.pp
-
Declaration:
- Procedure TDosStream.Read (Var Buf; Count: Sw_Word); Virtual;
-
Description:
- If the Stream is open and the stream status is stOK then Read will read Count bytes from
the stream and place them in Buf.
-
Errors:
- In case of an error, Status is set to StReadError, and ErrorInfo gets the OS specific error,
or 0 when an attempt was made to read beyond the end of the stream.
-
See also:
- TStream.Read (573), Write (581)
For an example, see TStream.Read (573).
-
Declaration:
- Procedure TDosStream.Write (Var Buf; Count: Sw_Word); Virtual;
-
Description:
- If the Stream is open and the stream status is stOK then Write will write Count bytes from
Buf and place them in the stream.
-
Errors:
- In case of an error, Status is set to StWriteError, and ErrorInfo gets the OS specific
error.
-
See also:
- TStream.Write (574), Read (581)
For an example, see TStream.Read (573).