mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 09:09:30 +02:00
+ Added tstringstream example (merged)
This commit is contained in:
parent
d678b3f0fe
commit
d1d1c8b0b2
@ -43,3 +43,4 @@ dsocksvr.pp Unix socket server application. Tests ssockets.
|
||||
sockcli.pp Unix socket client application. Tests TUnixStream in ssockets.
|
||||
isockcli.pp Inet socket server application. Tests TInetStream in ssockets.
|
||||
dsockcli.pp Dual socket server application. Tests ssockets.
|
||||
sstream.pp Tests TStringStream object.
|
43
fcl/tests/sstream.pp
Normal file
43
fcl/tests/sstream.pp
Normal file
@ -0,0 +1,43 @@
|
||||
Program TestStream;
|
||||
|
||||
uses classes;
|
||||
|
||||
Var Stream : TStringStream;
|
||||
S,T : AnsiString;
|
||||
|
||||
begin
|
||||
S:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
T:=S;
|
||||
Writeln ('Creating stream.');
|
||||
Stream:=TStringStream.Create(S);
|
||||
Writeln ('Initial Size : ',Stream.Size);
|
||||
Writeln ('Initial Position : ',Stream.Position);
|
||||
Writeln ('Setting new size to 100');
|
||||
Stream.Size:=100;
|
||||
Writeln ('New Size : ',Stream.Size);
|
||||
Writeln ('new Position : ',Stream.Position);
|
||||
Stream.WriteByte (1);
|
||||
Stream.WriteWord (2);
|
||||
Stream.WriteDWord (3);
|
||||
Stream.WriteString (S);
|
||||
Writeln ('Size after write : ',Stream.Size);
|
||||
Writeln ('Position after write : ',Stream.Position);
|
||||
Writeln ('Truncating size');
|
||||
Stream.Size:=Stream.Position;
|
||||
Writeln ('Stream Size is : ',Stream.Size);
|
||||
Writeln ('Stream Position : ',Stream.Position);
|
||||
Writeln ('Seek to position 0 : ', Stream.Seek(0,soFromBeginning));
|
||||
Writeln ('new Position : ',Stream.Position);
|
||||
If Stream.ReadByte<>1 then Writeln ('First byte not 1');
|
||||
If Stream.ReadWord<>2 then Writeln ('First word not 2');
|
||||
If Stream.ReadDWord<>3 then Writeln ('First Word not 3');
|
||||
T:=Stream.ReadString(Length(S));
|
||||
If Length(T)<>Length(S) then
|
||||
Writeln ('Couldn''t read string.');
|
||||
Stream.WriteByte (1);
|
||||
Stream.WriteWord (2);
|
||||
Stream.WriteDWord (3);
|
||||
Stream.WriteBuffer (S[1],Length(S));
|
||||
Writeln ('Stream Size is : ',Stream.Size);
|
||||
Stream.Free;
|
||||
end.
|
Loading…
Reference in New Issue
Block a user