Description | |
|
Provides both default Synchronous and selectable Asynchronous read/write access to a stream.
Streams can be of various types, such as files, pipes (given by their file handle - an Integer value) and standard input and output.
The two basic types of constructor take either the stream path or its numeric identifier - the handle.
Access can be controlled by the Access, Mode and Share parameters, along with optional control over the buffer size, and whether the access is Synchronous or Asnchronous where suppotred by the Operating System of the running machine.
Random access is supported via the Seek method.
Buffering is used for performance reasons.
Synchronous read and write is the default mode - it means that the current thread is tied up with the operation. Asynchronous operations immediately free up the current process - when the operation is complete, a routine of the current process is called to signal this completion. Asynchronous operation is somewhat beyond Delphi Basics.
|
|
Syntax | |
|
Constructor Create ( | PathString : String; Mode : FileMode ); | Constructor Create ( |
PathString : String; Mode : FileMode; Access : FileAccess ); | Constructor Create ( |
PathString : String; Mode : FileMode; Access : FileAccess; Share : FileShare ); | Constructor Create ( |
PathString : String; Mode : FileMode; Access : FileAccess; Share : FileShare; BufferSize : Integer ); | Constructor Create ( |
PathString : String; Mode : FileMode; Access : FileAccess; Share : FileShare; BufferSize : Integer; asynchronous : Boolean ); | Constructor Create ( |
FileHandle : IntPtr; Access : FileAccess ); | Constructor Create ( |
FileHandle : IntPtr; Access : FileAccess; Ownership : Boolean ); | Constructor Create ( |
FileHandle : IntPtr; Access : FileAccess; Ownership : Boolean; BufferSize : Integer ); | Constructor Create ( |
FileHandle : IntPtr; Access : FileAccess; Ownership : Boolean; BufferSize : Integer; Asynchronous : Boolean ); |
|
Methods | |
|
| BeginRead | Starts an asynchronous stream read operation |
| BeginWrite | Starts an asynchronous stream write operation |
| Close | Close the current stream |
| EndRead | Wait for an asynchronous read to complete |
| EndWrite | Wait for an asynchronous write to complete |
| Lock | Lock a section of the current stream to prevent others writing to it |
| Read | Reads the next block of bytes from the current stream |
| ReadByte | Read the next Byte from the current stream |
| Seek | Moves the current position in the current stream to the specified value |
| SetLength | Sets the length of the current stream |
| UnLock | UnLock a section of the current stream, allowing others to write to it |
| Write | Writes some or all bytes from a Byte Array into the current stream |
| WriteByte | Write a byte to the current stream |
|
|
|
Properties | |
|
CanRead | | Boolean | | Gets a value indicating whether the current stream supports reading. |
CanSeek | | Boolean | | Gets a value indicating whether the current stream supports seeking. |
CanWrite | | Boolean | | Gets a value indicating whether the current stream supports writing. |
Handle | | Integer | | Gets the operating system file handle for the file that the current FileStream object encapsulates. |
IsAsync | | Boolean | | Gets a value indicating whether the FileStream was opened asynchronously or synchronously. |
Length | | Int64 | | Gets the length in bytes of the stream. |
Name | | String | | Gets the name of the FileStream that was passed to the constructor. |
Position | | Int64 | | Gets or sets the current position of this stream. |
|
Delphi Basics links | |
|
|
Microsoft MSDN links | |
|
|