+ Added example for iostreams and tprocess

This commit is contained in:
michael 2000-02-10 20:47:26 +00:00
parent 1b1f3d5850
commit 8d3f033046
6 changed files with 88 additions and 13 deletions

View File

@ -1,5 +1,5 @@
#
# Makefile generated by fpcmake v0.99.13 [2000/02/09]
# Makefile generated by fpcmake v0.99.13 [2000/02/08]
#
defaultrule: all
@ -184,7 +184,7 @@ endif
# Targets
override EXEOBJECTS+=stringl dparser fstream mstream list threads testrtf cfgtest xmldump htdump testcgi tidea b64test b64test2 b64enc b64dec restest testz testz2
override EXEOBJECTS+=stringl dparser fstream mstream list threads testrtf cfgtest xmldump htdump testcgi tidea b64test b64test2 b64enc b64dec restest testz testz2 istream doecho testproc
ifeq ($(OS_TARGET),win32)
override EXEOBJECTS+=showver
endif
@ -793,16 +793,6 @@ override FPCOPT+=-Xs -OG2p3 -n
endif
endif
# Strip
ifdef STRIP
override FPCOPT+=-Xs
endif
# Optimizer
ifdef OPTIMIZE
override FPCOPT+=-OG2p3
endif
# Verbose settings (warning,note,info)
ifdef VERBOSE
override FPCOPT+=-vwni

View File

@ -5,7 +5,8 @@
[targets]
programs=stringl dparser fstream mstream list threads testrtf \
cfgtest xmldump htdump testcgi tidea \
b64test b64test2 b64enc b64dec restest testz testz2
b64test b64test2 b64enc b64dec restest testz testz2 \
istream doecho testproc
programs_win32=showver
rst=restest

View File

@ -34,3 +34,6 @@ b64enc.pp base64-encodes StdIn to StdOut (SG)
b64dec.pp base64-decodes StdIn to StdOut (SG)
restest.pp test program for resourcestrings with GNU gettext. (MVC)
(see also intl subdirectory)
istream.pp testprogram for input/output streams.
testproc.pp testprogram for TProcess object. Needs doecho to be compiled
also.

10
fcl/tests/doecho.pp Normal file
View File

@ -0,0 +1,10 @@
program doecho;
uses sysutils;
var r : integer;
begin
for r := 1 to 25 do
writeln ('Line : ', inttostr (r));
end.

43
fcl/tests/istream.pp Normal file
View File

@ -0,0 +1,43 @@
Program TestStream;
{
When testing, remember to send something through standard input !!
}
uses sysutils,classes,iostream;
Var Stream : TIOStream;
S,T : String;
i : longint;
SS : ShortString;
begin
S:='ABCDEFGHIJKLMNOPQRSTUVWXYZ %d'#10;
T:=S;
Writeln ('Creating output stream.');
Stream:=TIOStream.Create(iosOutPut);
For I:=1 to 10 do
begin
S:=Format(T,[I]);
Stream.WriteBuffer (S[1],Length(S));
end;
Stream.Free;
Writeln ('Creating error stream.');
Stream:=TIOStream.Create(iosError);
For I:=1 to 10 do
begin
S:=Format(T,[I]);
Stream.WriteBuffer (S[1],Length(S));
end;
Stream.Free;
Writeln ('Creating input stream');
Stream:=TIOStream.Create(iosInput);
SS:='aha';
While Length(SS)>0 do
begin
SetLength(SS,Stream.Read(SS[1],255));
Write(SS);
end;
Writeln ('Read ',Stream.Position,' bytes.');
Stream.Free;
end.

28
fcl/tests/testproc.pp Normal file
View File

@ -0,0 +1,28 @@
program testproc;
uses classes,process;
Const BufSize = 1024;
{$ifdef linux}
TheProgram = 'doecho';
{$else}
TheProgram = 'doecho.exe';
{$endif}
Var S : TProcess;
Buf : Array[1..BUFSIZE] of char;
I,Count : longint;
begin
S:=TProcess.Create(theprogram,[poExecuteOnCreate,poUsePipes]);
Repeat
Count:=s.output.read(buf,BufSize);
// reverse print for fun.
For I:=Count downto 1 do
write(buf[i]);
until Count<BufSize;
writeln;
S.Free;
end.