HandleStream¶
Qualified name: delphivcl.HandleStream
- class HandleStream¶
Bases:
Stream
THandleStream enables applications to read from and write to communications resources identified by a handle. Use THandleStream to access files, sockets, named pipes, mailslots, or other communications resources that provide a handle when opened. For example, the FileOpen function provides a handle for a file on disk. THandleStream allows applications to use a uniform stream interface when performing I/O using a handle. To avoid the overhead of managing file handles, use TFileStream to work with disk files.
Methods
Reads up to Count bytes of data from the resource associated with the handle stream into Buffer.
Read content as bytes.
Read content as float.
Read content as integer.
Read content as string.
Resets the current position of the handle stream.
Writes Count bytes from the Buffer to the current position in the resource.
Write content as bytes.
Write content as float.
Write content as integer.
Write content as string.
Attributes
Capabilities
StreamCapabilities:
Returns the TObject.ClassName
Specifies the handle for the communications resource the stream reads from and writes to.
Position
Indicates the current offset into the stream for reading and writing.
Size
Indicates the size in bytes of the stream.
- ClassName¶
Returns the TObject.ClassName
- Handle¶
Specifies the handle for the communications resource the stream reads from and writes to. Read Handle to get the handle for file management functions. To read from or write to the resource, use the methods of the THandleStream object. Handle is a read-only property. The handle property cannot be changed to allow the handle stream to switch from reading to writing or vice versa. For example, to change from a file handle that is opened in read-only mode to one that is opened in write mode:
Free the stream object. Call FileClose to close the file. Reopen the file in write mode and use the handle to create a new instance of a handle stream. Alternately, open a TFileStream object for the file, specifying a write mode for the stream. Note: Do not call the FileClose function on the Handle until after the THandleStream object has been destroyed.
- Type:
int
- Read(Buffer, Count: int) int ¶
Reads up to Count bytes of data from the resource associated with the handle stream into Buffer. Use Read to read data from the resource associated with the handle stream when the number of bytes in the file is not known. Read transfers up to Count bytes from the resource, starting at the current position, and then advances the current position in the resource by the number of bytes actually transferred. Read returns the number of bytes actually transferred, which may be less than Count if the end of file marker is encountered. All other data-reading methods of a handle stream (ReadBuffer, ReadComponent) call Read to do the actual reading.
- ReadBytes()¶
Read content as bytes.
- ReadFloat()¶
Read content as float.
- ReadInt()¶
Read content as integer.
- ReadString()¶
Read content as string.
- Seek(Offset: int, Origin: SeekOrigin) int ¶
Resets the current position of the handle stream. Use Seek to move the current position within the resource associated with the handle stream by the indicated offset. Seek allows an application to read from or write to a particular location within the resource. The Origin parameter indicates how to interpret the Offset parameter. Origin should be one of the following values:
Value
Meaning
soFromBeginning
Offset is from the beginning of the resource. Seek moves to the position Offset. Offset must be >= 0.
soFromCurrent
Offset is from the current position in the resource. Seek moves to Position + Offset.
soFromEnd
Offset is from the end of the resource. Offset must be <= 0 to indicate a number of bytes before the end of the file.
Or you can also use TSeekOrigin and its values to indicate where to start a seek operation. Seek returns the new value of the Position property, the new current position in the resource.
- Write(Buffer, Count: int) int ¶
Writes Count bytes from the Buffer to the current position in the resource. Use Write to write Count bytes to the resource associated with the handle stream, starting at the current position. After writing to the resource, Write advances the current position by the number bytes written, and returns the number of bytes written. All other data-writing methods of a handle stream (WriteBuffer, WriteComponent) call Write to do the actual writing.
- WriteBytes()¶
Write content as bytes.
- WriteFloat()¶
Write content as float.
- WriteInt()¶
Write content as integer.
- WriteString()¶
Write content as string.