From e0dd9f3c916b37d1fa23cf955e8821c9e6a2d0c2 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 30 May 1999 20:42:20 +0000 Subject: [PATCH] Format examples --- docs/sysutex/Makefile | 5 +- docs/sysutex/README | 4 + docs/sysutex/ex68.pp | 39 ++++++++ docs/sysutex/ex69.pp | 42 +++++++++ docs/sysutex/ex70.pp | 13 +++ docs/sysutex/ex71.pp | 200 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 301 insertions(+), 2 deletions(-) create mode 100644 docs/sysutex/ex68.pp create mode 100644 docs/sysutex/ex69.pp create mode 100644 docs/sysutex/ex70.pp create mode 100644 docs/sysutex/ex71.pp diff --git a/docs/sysutex/Makefile b/docs/sysutex/Makefile index d01a5b6cac..7fd205abc8 100644 --- a/docs/sysutex/Makefile +++ b/docs/sysutex/Makefile @@ -37,8 +37,9 @@ OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12\ ex25 ex26 ex27 ex28 ex29 ex30 ex31 ex32 ex33 ex34 ex35 ex36\ ex37 ex38 ex39 ex40 ex41 ex42 ex43 ex44 ex45 ex46 ex47\ ex48 ex49 ex50 ex51 ex52 ex53 ex54 ex55 ex56 ex57 ex58\ - ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 ex67 ex68 ex68 ex70\ -# ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 + ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 ex67 ex68 ex69 ex70\ + ex71 +# ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 TEXOBJECTS=$(addsuffix .tex, $(OBJECTS)) diff --git a/docs/sysutex/README b/docs/sysutex/README index 6f3744de31..ca81849601 100644 --- a/docs/sysutex/README +++ b/docs/sysutex/README @@ -67,3 +67,7 @@ ex64.pp contains an example of the BCDToInt function. ex65.pp contains an example of the CompareStr function. ex66.pp contains an example of the CompareText function. ex67.pp contains an example of the FloatToStr function. +ex68.pp contains an example of the FloatToStrF function. +ex69.pp contains an example of the FloatToText function. +ex70.pp contains an example of the FmtStr function. +ex71.pp contains an example of the Format function. diff --git a/docs/sysutex/ex68.pp b/docs/sysutex/ex68.pp new file mode 100644 index 0000000000..f24f70decd --- /dev/null +++ b/docs/sysutex/ex68.pp @@ -0,0 +1,39 @@ +Program Example68; + +{ This program demonstrates the FloatToStrF function } + +Uses sysutils; + +Const Fmt : Array [TFloatFormat] of string[10] = + ('general','exponent','fixed','number','Currency'); + +Procedure Testit (Value : Extended); + +Var I,J : longint; + FF : TFloatFormat; + +begin + For I:=5 to 15 do + For J:=1 to 4 do + For FF:=ffgeneral to ffcurrency do + begin + Write (Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : '); + Writeln (FloatToStrf(Value,FF,I,J)); + Write (-Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : '); + Writeln (FloatToStrf(-Value,FF,I,J)); + end; +end; + +Begin + Testit (1.1); + Testit (1.1E1); + Testit (1.1E-1); + Testit (1.1E5); + Testit (1.1E-5); + Testit (1.1E10); + Testit (1.1E-10); + Testit (1.1E15); + Testit (1.1E-15); + Testit (1.1E100); + Testit (1.1E-100); +End. \ No newline at end of file diff --git a/docs/sysutex/ex69.pp b/docs/sysutex/ex69.pp new file mode 100644 index 0000000000..69da74fbf5 --- /dev/null +++ b/docs/sysutex/ex69.pp @@ -0,0 +1,42 @@ +Program Example68; + +{ This program demonstrates the FloatToStrF function } + +Uses sysutils; + +Const Fmt : Array [TFloatFormat] of string[10] = + ('general','exponent','fixed','number','Currency'); + +Procedure Testit (Value : Extended); + +Var I,J : longint; + FF : TFloatFormat; + S : ShortString; + +begin + For I:=5 to 15 do + For J:=1 to 4 do + For FF:=ffgeneral to ffcurrency do + begin + Write (Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : '); + SetLength(S,FloatToText (@S[1],Value,FF,I,J)); + Writeln (S); + Write (-Value,'(Prec: ',I:2,', Dig: ',J,', fmt : ',Fmt[ff],') : '); + SetLength(S,FloatToText (@S[1],-Value,FF,I,J)); + Writeln (S); + end; +end; + +Begin + Testit (1.1); + Testit (1.1E1); + Testit (1.1E-1); + Testit (1.1E5); + Testit (1.1E-5); + Testit (1.1E10); + Testit (1.1E-10); + Testit (1.1E15); + Testit (1.1E-15); + Testit (1.1E100); + Testit (1.1E-100); +End. \ No newline at end of file diff --git a/docs/sysutex/ex70.pp b/docs/sysutex/ex70.pp new file mode 100644 index 0000000000..df0a1af1b8 --- /dev/null +++ b/docs/sysutex/ex70.pp @@ -0,0 +1,13 @@ +Program Example70; + +{ This program demonstrates the FmtStr function } + +Uses sysutils; + +Var S : AnsiString; + +Begin + S:=''; + FmtStr (S,'For some nice examples of fomatting see %s.',['Format']); + Writeln (S); +End. \ No newline at end of file diff --git a/docs/sysutex/ex71.pp b/docs/sysutex/ex71.pp new file mode 100644 index 0000000000..c6cf488550 --- /dev/null +++ b/docs/sysutex/ex71.pp @@ -0,0 +1,200 @@ +Program dof; + +Uses sysutils; + +Var P : Pointer; + fmt,S : string; + +Procedure TestInteger; + +begin + Try + Fmt:='[%d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%%]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%10d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + fmt:='[%.4d]';S:=Format (fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%10.4d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10.4d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10d]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10.4d]';S:=Format (fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%-*.*d]';S:=Format (fmt,[4,5,10]);writeln(Fmt:12,' => ',s); + except + On E : Exception do + begin + Writeln ('Exception caught : ',E.Message); + end; + end; + writeln ('Press enter'); + readln; +end; + +Procedure TestHexaDecimal; + +begin + try + Fmt:='[%x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%10x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%10.4x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10.4x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10x]';S:=Format (Fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10.4x]';S:=Format (fmt,[10]);writeln(Fmt:12,' => ',s); + Fmt:='[%-*.*x]';S:=Format (fmt,[4,5,10]);writeln(Fmt:12,' => ',s); + except + On E : Exception do + begin + Writeln ('Exception caught : ',E.Message); + end; + end; + writeln ('Press enter'); + readln; +end; + +Procedure TestPointer; + +begin + P:=Pointer(1234567); + try + Fmt:='[0x%p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s); + Fmt:='[0x%10p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s); + Fmt:='[0x%10.4p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s); + Fmt:='[0x%0:p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s); + Fmt:='[0x%0:10p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s); + Fmt:='[0x%0:10.4p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s); + Fmt:='[0x%0:-10p]';S:=Format (Fmt,[P]);writeln(Fmt:12,' => ',s); + Fmt:='[0x%0:-10.4p]';S:=Format (fmt,[P]);writeln(Fmt:12,' => ',s); + Fmt:='[%-*.*p]';S:=Format (fmt,[4,5,P]);writeln(Fmt:12,' => ',s); + except + On E : Exception do + begin + Writeln ('Exception caught : ',E.Message); + end; + end; + writeln ('Press enter'); + readln; +end; + +Procedure TestString; + +begin + try + Fmt:='[%s]';S:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s); + fmt:='[%0:s]';s:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s); + fmt:='[%0:18s]';s:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s); + fmt:='[%0:-18s]';s:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s); + fmt:='[%0:18.12s]';s:=Format(fmt,['This is a string']);Writeln(fmt:12,'=> ',s); + fmt:='[%-*.*s]';s:=Format(fmt,[18,12,'This is a string']);Writeln(fmt:12,'=> ',s); + except + On E : Exception do + begin + Writeln ('Exception caught : ',E.Message); + end; + end; + writeln ('Press enter'); + readln; +end; + +Procedure TestExponential; + +begin + Try + Fmt:='[%e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%10e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%10.4e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10.4e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10e]';S:=Format (Fmt,[1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10.4e]';S:=Format (fmt,[1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%-*.*e]';S:=Format (fmt,[4,5,1.234]);writeln(Fmt:12,' => ',s); + except + On E : Exception do + begin + Writeln ('Exception caught : ',E.Message); + end; + end; + writeln ('Press enter'); + readln; +end; + +Procedure TestNegativeExponential; + +begin + Try + Fmt:='[%e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%10e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%10.4e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10.4e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10e]';S:=Format (Fmt,[-1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10.4e]';S:=Format (fmt,[-1.234]);writeln(Fmt:12,' => ',s); + Fmt:='[%-*.*e]';S:=Format (fmt,[4,5,-1.234]);writeln(Fmt:12,' => ',s); + except + On E : Exception do + begin + Writeln ('Exception caught : ',E.Message); + end; + end; + writeln ('Press enter'); + readln; +end; + +Procedure TestSmallExponential; + +begin + Try + Fmt:='[%e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%10e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%10.4e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10.4e]';S:=Format (Fmt,[0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10e]';S:=Format (Fmt,[0.0123]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10.4e]';S:=Format (fmt,[0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%-*.*e]';S:=Format (fmt,[4,5,0.01234]);writeln(Fmt:12,' => ',s); + except + On E : Exception do + begin + Writeln ('Exception caught : ',E.Message); + end; + end; + writeln ('Press enter'); + readln; +end; + +Procedure TestSmallNegExponential; + +begin + Try + Fmt:='[%e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%10e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%10.4e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:10.4e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10e]';S:=Format (Fmt,[-0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%0:-10.4e]';S:=Format (fmt,[-0.01234]);writeln(Fmt:12,' => ',s); + Fmt:='[%-*.*e]';S:=Format (fmt,[4,5,-0.01234]);writeln(Fmt:12,' => ',s); + except + On E : Exception do + begin + Writeln ('Exception caught : ',E.Message); + end; + end; + writeln ('Press enter'); + readln; +end; + +begin + TestInteger; + TestHexadecimal; + TestPointer; + TestExponential; + TestNegativeExponential; + TestSmallExponential; + TestSmallNegExponential; +end. \ No newline at end of file