unit Streaming;
interface
uses Sysutils, Classes;
Type
TMemoryStreamExt =
class(TMemoryStream)
public
procedure WriteStringToStream(aStr :
String);
function ReadStringFromStream :
String;
end;
TFileStreamExt =
class(TFilestream)
public
procedure WriteStringToStream(aStr :
String);
function ReadStringFromStream :
String;
end;
implementation
{ TFileStreamExt }
procedure TFileStreamExt.WriteStringToStream(aStr :
String);
var
aStrLen : Integer;
begin
aStrLen:=Length(aStr);
WriteBuffer(aStrLen,SizeOf(Integer));
WriteBuffer(Pointer(aStr)^,aStrLen);
end;
function TFileStreamExt.ReadStringFromStream:
String;
var
aStrLen : Integer;
begin
ReadBuffer(aStrLen,SizeOf(Integer));
SetLength(Result,aStrLen);
ReadBuffer(Pointer(Result)^,aStrLen);
end;
{ TMemoryStreamExt }
function TMemoryStreamExt.ReadStringFromStream:
String;
var
aStrLen : Integer;
begin
ReadBuffer(aStrLen,SizeOf(Integer));
SetLength(Result,aStrLen);
ReadBuffer(Pointer(Result)^,aStrLen);
end;
procedure TMemoryStreamExt.WriteStringToStream(aStr:
String);
var
aStrLen : Integer;
begin
aStrLen:=Length(aStr);
WriteBuffer(aStrLen,SizeOf(Integer));
WriteBuffer(Pointer(aStr)^,aStrLen);
end;
end.