uses System.SysUtils, System.Classes;
function writeStringThings(): TStream;
var
data: TBytes;
begin
Result := TMemoryStream.Create();
try
data := TEncoding.Unicode.GetBytes('
Name des Datensatzes');
Result.WriteData( Length(data) );
Result.
Write(data, Length(data));
data := TEncoding.ASCII.GetBytes('
12345;67890');
Result.WriteData( Length(data) );
Result.
Write(data, Length(data));
except
Result.Destroy();
raise;
end;
end;
procedure readStringThings(
const fromStream: TStream);
var
content:
String;
buffer: TBytes;
dataLength: Integer;
begin
fromStream.Seek(0, TSeekOrigin.soBeginning);
// Datensatz Name
fromStream.
Read(dataLength, Integer.Size);
SetLength(buffer, dataLength);
fromStream.
Read(buffer, dataLength);
content := TEncoding.Unicode.GetString(buffer);
WriteLn( content.QuotedString() );
// Sparsamer String
fromStream.
Read(dataLength, Integer.Size);
SetLength(buffer, dataLength);
fromStream.
Read(buffer, dataLength);
content := TEncoding.ASCII.GetString(buffer);
WriteLn( content.QuotedString() );
end;
var
stream: TStream;
begin
try
stream := writeStringThings();
try
readStringThings(stream);
finally
stream.Destroy();
end;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
writeln('
end.'); readln;
end.