In Delphi, TStream is the base class for a set of classes that represent streams of data. A stream is a sequence of bytes that can be read from or written to. TStream provides a set of methods and properties that allow you to read and write data to a stream, as well as seek to a specific position within the stream.
TMemoryStream is a subclass of TStream that stores the stream data in memory. You can use a TMemoryStream to read from or write to a stream of data that is stored in memory, rather than on disk or over a network.
To create a TMemoryStream, you can use the following syntax;
1 2 3 4 |
var ms : TMemoryStream; begin ms := TMemoryStream.Create; |
You can then use the Write and Read methods of TMemoryStream to write data to and read data from the stream. For example
1 2 |
ms.Write(Buffer, SizeOf(Buffer)); ms.Read(Buffer, SizeOf(Buffer)); |
You can also use the Position property of TMemoryStream to seek to a specific position within the stream, and the Size property to determine the current size of the stream.
TStringStream is another subclass of TStream that allows you to read from and write to a stream of data that is stored in a string. To create a TStringStream, you can use the following syntax
1 2 3 4 |
var ss: TStringStream; begin ss := TStringStream.Create(‘Hello, world!’); |
You can then use the Read and Write methods of TStringStream to read from and write to the string. For example
1 2 |
s := ss.ReadString(ss.Size); ss.WriteString(‘Hello, world!’); |
You can also use the Position property of TStringStream to seek to a specific position within the string, and the Size property to determine the current size of the string.
Leave a Reply