Scanf for Delphi
Formatted input routines
Since its stone-age days, C language offered two complementary functions
for text processing: printf ("print formatted") and scanf
("scan formatted"). Beginning with Turbo Pascal 6.0, a printf-like
utility Format has become avilable and proved very useful.
Unfortunately, even with Delphi 4, there is no scanf counterpart.
One of the ways to solve this problem would be to make a binary (OBJ or
DLL) under C and link it with Delphi. This solution is not ideal for three
reasons:
-
scanf function uses calls to many other functions in the
C run-time library. Linking it to Delphi would require the application
either to carry a large additional DLL with it, or to incorporate all this
into the executable.
-
scanf function does not implement many Delphi constructs:
from string types, only PChar is supported, and dollar
sign is not recognized as hex prefix.
-
You must have a licence to add the C run-time library to your product,
in other words, buy a C compiler.
Scanf for Delphi is a native
Delphi code for D2, D3 and D4. The package introduces following
routines:
-
sscanf ("string scanf") compatible to the original C sscanf
and using C syntax for the format string. Its main purpose is
to make porting of C code to Delphi as easy as possible.
-
fscanf ("file scanf") corresponds to the sscanf,
using TStream as input.
-
DeFormat which uses the syntax of the Format
procedure.
-
DeFormatBuf and StrDeFmt, obvious counterparts
of FormatBuf and StrFmt.
-
Int64ToStr, Int64ToHex, and Int64ToOct,
providing output of the Comp type as decimal, hex, and
octal integer for Delphi 2 and Delphi 3 (Delphi 4 has a built-in
int64 type).
-
TextToFloatS, StrToFloatS, and StrToCurrS
as extensins to the library functions TextToFloat, StrToFloat, and
StrToCurr, providing support for thousand separators.
-
StrToCurrF as a futher extension to StrToCurr,
providing input for the formatted Currency type (e.g. 123,456.23
$-).
Scanf and DeFormat extend functionality
of their prototypes, when it does not interfere with compatibility: scanf
supports ShortString and AnsiString,
and recognizes dollar sign as hex prefix, while DeFormat
also accepts 0x and 0X hex prefices.
For more precise information as well as for the instruction to use,
please read the readme.txt file in the package.
Current version is 1.0 and includes full source code.
The package is free for private and academic usage.
For commercial usage, contact the author
for a licence.
The primary site for Scanf for Delphi
is
but you may download it from here as well.