Overload List
| # | Signature | Description |
|---|---|---|
| 1 | procedure SaveToStream(const Stream: TStream); overload; | Writes Text to Stream in Encoding (the encoding of the last load), else DefaultEncoding. |
| 2 | procedure SaveToStream(const Stream: TStream; const Encoding: TEncoding); overload; | Writes Text to Stream at its position in Encoding, after the encoding's byte order mark while WriteBOM; nil writes in DefaultEncoding. |
Overload 1: procedure SaveToStream(const Stream: TStream); overload;
Writes Text to Stream in Encoding (the encoding of the last load), else DefaultEncoding.
| # | Name | Description |
|---|---|---|
| 1 | Stream | The stream, written at its position. |
Result: stored in self (calling object)
As SaveToStream(Stream, Encoding) otherwise.
var b: Matrix;
AStream: TFileStream;
begin
b := [[0,0,1,3,2]];
AStream := TFileStream.Create('C:\test.Vec',fmCreate);
try
b.SaveToStream(AStream); // Write info and header for b
finally
AStream.Free;
end
end;
Overload 2: procedure SaveToStream(const Stream: TStream; const Encoding: TEncoding); overload;
Writes Text to Stream at its position in Encoding, after the encoding's byte order mark while WriteBOM; nil writes in DefaultEncoding.
| # | Name | Description |
|---|---|---|
| 1 | Stream | The stream, written at its position. |
| 2 | Encoding | The encoding to write in; nil writes in DefaultEncoding. |
Result: stored in self (calling object)
No string is built. For UTF-8, UTF-16, and TEncoding.ANSI or TEncoding.ASCII on a single-byte code page, the items are converted ChunkSize bytes of text at a time, in memory of about two and a half times ChunkSize, whatever the number of items. Any other encoding converts the whole text at once. The list keeps that memory for its next save or load, which takes more only for more text, until Compact. A text the encoding cannot write raises EEncodingError; what was written before it stays in the stream.
UTF-8 without a byte order mark.
uses Substr, System.SysUtils, System.Classes;
procedure Example;
var List: TSubstringList;
Stream: TBytesStream;
begin
List := TSubstringList.Create(2);
Stream := TBytesStream.Create;
try
List.Add('ab');
List.WriteBOM := False;
List.SaveToStream(Stream, TEncoding.UTF8);
Assert(Stream.Size = 4);
Assert((Stream.Bytes[0] = Ord('a')) and (Stream.Bytes[3] = 10));
finally
Stream.Free;
List.Free;
end;
end;