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

Create

Creates an instance of THandleStream.

Free

Frees the Wrapped Delphi Object

InheritsFrom

Returns True if Delphi Object is or inherits from ClassName

Read

Reads up to Count bytes of data from the resource associated with the handle stream into Buffer.

ReadBytes

Read content as bytes.

ReadFloat

Read content as float.

ReadInt

Read content as integer.

ReadString

Read content as string.

Seek

Resets the current position of the handle stream.

SetProps

Sets several properties in one call

ToList

If the object is a container (TStrings, TComponent...), it returns the content of the sequence as a Python list object.

ToTuple

If the object is a container (TStrings, TComponent...), it returns the content of the sequence as a Python tuple object.

Write

Writes Count bytes from the Buffer to the current position in the resource.

WriteBytes

Write content as bytes.

WriteFloat

Write content as float.

WriteInt

Write content as integer.

WriteString

Write content as string.

Attributes

ClassName

Returns the TObject.ClassName

Handle

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

Create(AHandle: NativeUInt)#

Creates an instance of THandleStream. Call Create to instantiate a THandleStream for a given handle. The handle must be obtained by opening or creating the resource in the appropriate mode. For example, to create a handle stream for reading from a file, obtain the file handle by opening the file with an fmOpenRead or fmOpenReadWrite mode. To create a handle stream for writing to a file, obtain the file handle by opening the file with an fmOpenWrite or fmOpenReadWrite mode.

Free()#

Frees the Wrapped Delphi Object

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.

InheritsFrom(ClassName)#

Returns True if Delphi Object is or inherits from ClassName

Read(Buffer, Count: Integer) Integer#

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: Int64, Origin: SeekOrigin) Int64#

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.

SetProps(prop1=val1, prop2=val2...)#

Sets several properties in one call

ToList()#

If the object is a container (TStrings, TComponent…), it returns the content of the sequence as a Python list object.

ToTuple()#

If the object is a container (TStrings, TComponent…), it returns the content of the sequence as a Python tuple object.

Write(Buffer, Count: Integer) Integer#

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.