CustomMemoryStream#

Qualified name: delphivcl.CustomMemoryStream

class CustomMemoryStream#

Bases: Stream

TCustomMemoryStream is an abstract base class used as the common ancestor for memory streams. Use TCustomMemoryStream as a base class when defining a stream object that can transfer data that is stored in memory. Memory streams are useful for providing file-like access to data that is stored in a less accessible medium. Data can be moved to an internal memory buffer when the memory stream is created. After manipulating the data in a memory stream, the data can be written out to its actual storage medium when the memory stream is destroyed. Do not instantiate an instance of TCustomMemoryStream. It is an abstract class that implements behavior common to all memory streams. To work with an instance of a memory stream, use one of the descendants of TCustomMemoryStream, such as TMemoryStream or TResourceStream.

Methods

Free

Frees the Wrapped Delphi Object

InheritsFrom

Returns True if Delphi Object is or inherits from ClassName

Read

Reads up to Count bytes from the memory stream into Buffer and advances the current position of the stream by the number of bytes read.

ReadBytes

Read content as bytes.

ReadFloat

Read content as float.

ReadInt

Read content as integer.

ReadString

Read content as string.

SaveToFile

Writes the entire contents of the memory stream to the file with a given file name.

SaveToStream

Writes the entire contents of the memory stream to the stream object specified by Stream.

Seek

Moves the current position of the stream by Offset bytes, relative to the origin specified by Origin.

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.

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

Memory

Provides direct access to the memory pool allocated for the memory stream.

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

Free()#

Frees the Wrapped Delphi Object

InheritsFrom(ClassName)#

Returns True if Delphi Object is or inherits from ClassName

Memory#

Provides direct access to the memory pool allocated for the memory stream. Use Memory to get access to the memory for the stream. The memory for the stream holds the data that is being transferred by means of the memory stream. Size is the number of bytes of Memory that were allocated, and Position is the current position within Memory.

Note: Memory is a read-only property. Memory can be used to change the contents of the memory, but to set the actual memory the stream works with, descendants of TCustomMemoryStream must assign a pointer to a memory buffer by calling the SetPointer method.

Read(Buffer, Count: Integer) Integer#

Reads up to Count bytes from the memory stream into Buffer and advances the current position of the stream by the number of bytes read. Use Read to read the contents of the memory stream into a buffer, starting at the current position. Read will read up to Count bytes from the current position in Memory. If Count bytes extends beyond the end of the memory buffer, Read will only transfer the data up to the end of the associated memory buffer. Read returns the number of bytes actually transferred to Buffer, and advances the current position accordingly. If the return value is less than Count, it means that reading reached the end of the stream data. All the other data-reading methods of the memory stream (ReadBuffer, ReadComponent) call Read to do the actual reading.

Note: Read treats Count as an upper bound. The ReadBuffer method, by contrast, raises an exception if Count bytes cannot be read.

ReadBytes()#

Read content as bytes.

ReadFloat()#

Read content as float.

ReadInt()#

Read content as integer.

ReadString()#

Read content as string.

SaveToFile(FileName: string)#

Writes the entire contents of the memory stream to the file with a given file name. Use SaveToFile to write the contents of Memory to a file. SaveToFile allows an application to write out the contents of the memory stream without having to explicitly create and free a file stream object. In case the file already exists, the current file contents will be completely replaced with the new. If the named file cannot be created or opened, SaveToFile raises an EFCreateError exception.

SaveToStream(Stream: Stream)#

Writes the entire contents of the memory stream to the stream object specified by Stream. Use SaveToStream to copy data that is stored in memory into another storage medium. SaveToStream writes the entire contents of Memory into the indicated stream object, starting at the current position in the stream that was passed as a parameter. When the Stream parameter is a TFileStream object, SaveToStream does much the same thing as the SaveToFile method. However, SaveToStream writes to the current position in the target stream. Thus, for example, SaveToStream can be used to append the contents of Memory to a file stream, rather than replace the contents of the file the way SaveToFile does. If the entire contents of the memory stream cannot be written to the target stream, SaveToStream raises an EWriteError exception.

Seek(Offset: Int64, Origin: SeekOrigin) Int64#

Moves the current position of the stream by Offset bytes, relative to the origin specified by Origin. Use Seek to move the current position within the memory stream by the indicated offset. Seek allows an application to read from or write to a particular location within the Memory associated with the memory stream. If Offset is a negative number, the seeking is backward from the specified origin. The following table shows the different values of Origin and their meanings for seeking:

Value

Meaning

soBeginning

Offset is from the beginning of Memory. Seek moves to the position Offset. Offset must be >= 0.

soCurrent

Offset is from the current position. Seek moves to Position + Offset.

soEnd

Offset is from the end of Memory. Offset must be <= 0 to indicate a number of bytes before the end of the memory buffer.

Seek returns the new value of the Position property.

Note: Seek does no error checking on the value provided for Offset. Do not call Seek with an offset that would move the current position less than 0 (before the start of Memory) or greater than Size (beyond the end of the memory buffer).

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.

WriteBytes()#

Write content as bytes.

WriteFloat()#

Write content as float.

WriteInt()#

Write content as integer.

WriteString()#

Write content as string.