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:
  1. 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.
  2. scanf  function does not implement many Delphi constructs: from string types, only PChar is supported, and dollar sign is not recognized as hex prefix.
  3. 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:

  1. 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.
  2. fscanf ("file scanf") corresponds to the sscanf, using TStream as input.
  3. DeFormat which uses the syntax of the Format procedure.
  4. DeFormatBuf and StrDeFmt, obvious counterparts of  FormatBuf and StrFmt.
  5. 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).
  6. TextToFloatS, StrToFloatS, and StrToCurrS as extensins to the library functions TextToFloat, StrToFloat, and StrToCurr, providing support for thousand separators.
  7. 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 Torry's Delphi Pages at www.torry.ru  but you may download it from here as well. 1