home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sibylft1.zip / DOC.DAT / DOC / SPCC / SYSUTILS.PAS < prev    next >
Pascal/Delphi Source File  |  1997-04-07  |  70KB  |  1,741 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. { Speed-Pascal 1.5 Runtime Library                      }
  5. { System Utilities Unit (Delphi compatible)             }
  6. {                                                       }
  7. { (c) 1995-96 Joerg Pleumann                            }
  8. { (c) 1996    SpeedSoft                                 }
  9. {                                                       }
  10. { Please mail all bugs and suggestions to:              }
  11. {                                                       }
  12. { Internet: sa021pl @ uni-duisburg.de                   }
  13. { FidoNet:  Joerg Pleumann @ 2:2448/136.6               }
  14. {                                                       }
  15. {*******************************************************}
  16.  
  17. unit SysUtils;
  18.  
  19. { Define compiler symbol GR to include German resource file.
  20.   Otherwise the default (English) resource file will be used. }
  21.  
  22. {$ifdef gr}
  23.   {$r German}
  24. {$else gr}
  25.   {$r English}
  26. {$endif gr}
  27.  
  28. interface
  29.  
  30. { Define compiler symbol GUI to include functions from
  31.   OS/2 PM API. If you need a version of SysUtils that
  32.   uses only OS/2 base API functions (and therefore lacks
  33.   some features), comment this line out and recompile the
  34.   unit. Change this to produce programs that run without
  35.   the OS/2 PM being active (may also need changes in
  36.   System unit). Normally you shouldn't change this. }
  37.  
  38. {$define GUI}
  39.  
  40. {$ifdef OS2}
  41.   {$ifdef GUI}
  42. uses
  43.   Os2Def,BseDos, BseErr, PmWin, PmShl;
  44.   {$else GUI}
  45. uses
  46.   Os2Def,BseDos, BseErr;
  47.   {$endif GUI}
  48. {$endif OS2}
  49.  
  50. {$ifdef WIN95}
  51. uses
  52.   WinNT, WinBase, WinUser;
  53. {$endif WIN95}
  54.  
  55. { Constants for spcc notification and error messages and month / day names. }
  56. {$I SPCC.INC}
  57.  
  58. type
  59.   { Pointer to floating point value. }
  60.   PExtended = ^Extended;
  61.  
  62. type
  63.   //Override Exception definition from system to allow formatted create...
  64.   Exception=class(SysException)
  65.      public
  66.          constructor CreateFmt(const Msg:string;const Args:array of const);
  67.          constructor CreateRes(Ident:WORD);
  68.          constructor CreateResFmt(Ident:WORD;const Args:array of const);
  69.          constructor CreateResNLS(Ident:WORD);
  70.          constructor CreateResNLSFmt(Ident:WORD;const Args:array of const);
  71.          constructor CreateHelp(const Msg:string;AHelpContext:LONGINT);
  72.          constructor CreateFmtHelp(const Msg:string;const Args:array of const;AHelpContext:LONGINT);
  73.          constructor CreateResHelp(Ident:WORD;AHelpContext:LONGINT);
  74.          constructor CreateResFmtHelp(Ident:WORD;const Args:array of const;AHelpContext:LONGINT);
  75.          constructor CreateResNLSHelp(Ident:WORD;AHelpContext:LONGINT);
  76.          constructor CreateResNLSFmtHelp(Ident:WORD;const Args:array of const;AHelpContext:LONGINT);
  77.   end;
  78.  
  79.   ExceptClass = class OF Exception;
  80.  
  81.   EConvertError = class(Exception);
  82.  
  83. const
  84.  
  85. { File open modes - A legal file open mode is a logical combination
  86.   of an open mode and a sharing mode. Please note that OS/2 normally
  87.   doesn't allow fmShareCompat, but for reasons of compatibility the
  88.   file functions automatically replace this constant by
  89.   fmShareDenyNone. }
  90.  
  91.   {$ifdef OS2}
  92.   fmOpenRead       = $0000;
  93.   fmOpenWrite      = $0001;
  94.   fmOpenReadWrite  = $0002;
  95.   fmShareCompat    = $0000;
  96.   fmShareExclusive = $0010;
  97.   fmShareDenyWrite = $0020;
  98.   fmShareDenyRead  = $0030;
  99.   fmShareDenyNone  = $0040;
  100.   {$endif}
  101.  
  102.   {$ifdef Win95}
  103.   fmOpenRead       = $80000000;
  104.   fmOpenWrite      = $40000000;
  105.   fmOpenReadWrite  = $C0000000;
  106.   fmShareCompat    = $00000003;
  107.   fmShareExclusive = $00000000;
  108.   fmShareDenyWrite = $00000001;
  109.   fmShareDenyRead  = $00000002;
  110.   fmShareDenyNone  = $00000003;
  111.   {$endif}
  112.  
  113. { File attribute constants - Please note that there is no constant
  114.   faVolumeID, since OS/2 handles volume IDs in another way than DOS
  115.   does. }
  116.  
  117.   faReadOnly       = $0001;
  118.   faHidden         = $0002;
  119.   faSysFile        = $0004;
  120.   faDirectory      = $0010;
  121.   faArchive        = $0020;
  122.  
  123.   faAnyFile        = faReadOnly or faHidden or faSysFile or faDirectory or faArchive;
  124.  
  125. { 'Must' attribute constants - OS/2-specific file attribute constants
  126.   for searching files. Use these constants in logical combination
  127.   with the normal file attributes when calling FindFirst() to restrict
  128.   the search results. }
  129.  
  130.   faMustReadOnly   = $0100;
  131.   faMustHidden     = $0200;
  132.   faMustSysFile    = $0400;
  133.   faMustDirectory  = $1000;
  134.   faMustArchive    = $2000;
  135.  
  136. const
  137.  
  138. { File lock-timeout - This timeout value is used when performing file
  139.   locking / unlocking operations. Value is given in ms. }
  140.  
  141.   LockTimeout: LongInt = 5000;
  142.  
  143. type
  144.  
  145. { Support for date and time operations - Both values are stored in
  146.   one floating point value. The integer part contains the days passed
  147.   since 31-Dec-0000, assuming that the Gregorian calendar has always
  148.   been used. The fractional part contains the part of the day since
  149.   00:00:00. The time part is always equal to or greater than zero
  150.   and smaller than one. }
  151.  
  152.   TDateTime = Extended;
  153.  
  154. const
  155.  
  156.   SecsPerDay = 24 * 60 * 60;
  157.   MSecsPerDay = SecsPerDay * 1000;
  158.  
  159. type
  160.  
  161. { Some type conversion records. }
  162.  
  163.   WordRec = record
  164.     Lo, Hi: Byte;
  165.   end;
  166.  
  167.   LongRec = record
  168.     Lo, Hi: Word;
  169.   end;
  170.  
  171.   TMethod = record
  172.     Code, Data: Pointer;
  173.   end;
  174.  
  175. { Some useful arrays. }
  176.  
  177.   PByteArray = ^TByteArray;
  178.   TByteArray = array[0..MaxLongInt] of Byte;
  179.  
  180.   PWordArray = ^TWordArray;
  181.   TWordArray = array[0..MaxLongInt div 2] of Word;
  182.  
  183. { Generic procedure type. }
  184.  
  185.   TProcedure = procedure;
  186.  
  187. { Generic filename type }
  188.  
  189.   TFileName = string;
  190.  
  191. { File search record - This is the data structure internally used
  192.   by the FindFirst, FindNext, and FindClose functions. }
  193.  
  194.   TSearchRec = record
  195.     {$IFDEF Win95}
  196.     InternalAttr:LongWord;
  197.     SearchRecIntern:WIN32_FIND_DATA;
  198.     {$ENDIF}
  199.     HDir: LongWord;
  200.     Attr: Byte;
  201.     Time: Longint;
  202.     Size: Longint;
  203.     Name: string;
  204.   end;
  205.  
  206. { FloatToText codes - These codes are used to specify the basic
  207.   output format of the various functions that convert floating
  208.   point values to strings. }
  209.  
  210.   TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  211.  
  212. { FloatToDecimal result record - This record is used to hold the return
  213.   value of the FloatToDecimal function. }
  214.  
  215.   TFloatRec = record
  216.     Exponent: Integer;
  217.     Negative: Boolean;
  218.     Digits: array[0..18] of Char;
  219.   end;
  220.  
  221. const
  222.  
  223. { Empty string and pointer to empty string - Used internally by various
  224.   string functions. }
  225.  
  226.   EmptyStr: string[1] = '';
  227.   NullStr: PString = @EmptyStr;
  228.  
  229. var
  230.  
  231. { --- Date, time, and currency defaults ---
  232.  
  233.   The following global variables contain default values for formatting
  234.   date, time, and currency values. Most of them are queried from the
  235.   system at program startup. Some others are taken from the
  236.   application's resources. }
  237.  
  238. { DateSeparator - The character used to separate year, month, and day,
  239.   when converting a TDateTime value to text. Queried from the system
  240.   at program startup. }
  241.  
  242.   DateSeparator: Char;
  243.  
  244. { ShortDateFormat - The default format string used when converting a
  245.   TDateTime value to text. This one is used whenever a short result
  246.   is desired. The value is computed at program startup. }
  247.  
  248.   ShortDateFormat: string[15];
  249.  
  250. { LongDateFormat - The default format string used when converting a
  251.   TDateTime value to text. This one is used whenever a long result
  252.   is desired. The value is computed at program startup. }
  253.  
  254.   LongDateFormat: string[31];
  255.  
  256. { ShortMonthNames - Abbreviations for month names used when converting
  257.   a TDateTime value to text. The names are taken from the program's
  258.   resources. }
  259.  
  260.   ShortMonthNames: array[1..12] of string[7];
  261.  
  262. { LongMonthNames - The full month names used when converting a
  263.   TDateTime value to text. The names are taken from the program's
  264.   resources. }
  265.  
  266.   LongMonthNames: array[1..12] of string[15];
  267.  
  268. { ShortDayNames - Abbreviations for day names used when converting
  269.   a TDateTime value to text. The names are taken from the program's
  270.   resources. }
  271.  
  272.   ShortDayNames: array[1..7] of string[7];
  273.  
  274. { LongDayNames - The full day names used when converting a TDateTime
  275.   value to text. The names are taken from the program's resources. }
  276.  
  277.   LongDayNames: array[1..7] of string[15];
  278.  
  279. { DateOrder - The order of year, month, and day assumed when trying to
  280.   extract date information from a string. Queried from the system at
  281.   program startup. }
  282.  
  283.   DateOrder: Byte;
  284.  
  285. { TimeSeparator - The character used to separate hour, minute, and
  286.   second, when converting a TDateTime value to text. Queried from the
  287.   system at program startup. }
  288.  
  289.   TimeSeparator: Char;
  290.  
  291. { TimeAMString - The string appended to time values between 00:00 and
  292.   11:59 when converting a DateTime value to text. Only used when
  293.   12-hour clock format is used. Queried from the system at program
  294.   startup. }
  295.  
  296.   TimeAMString: string[7];
  297.  
  298. { TimePMString - The string appended to time values between 12:00 and
  299.   23:59 when converting a DateTime value to text. Only used when
  300.   12-hour clock format is used. Queried from the system at program
  301.   startup. }
  302.  
  303.   TimePMString: string[7];
  304.  
  305. { ShortTimeFormat - The default format string used when converting a
  306.   TDateTime value to text. This one is used whenever a shorter result
  307.   is desired. Queried from the system at program startup. }
  308.  
  309.   ShortTimeFormat: string[15];
  310.  
  311. { LongTimeFormat - The default format string used when converting a
  312.   TDateTime value to text. This one is used whenever a longer result
  313.   is desired. Queried from the system at program startup. }
  314.  
  315.   LongTimeFormat: string[31];
  316.  
  317. { TwelveHours - Indicates whether 12-hour clock format is used when
  318.   trying to extract time information from a string. Queried from
  319.   the system at program startup. }
  320.  
  321.   TwelveHours: Boolean;
  322.  
  323. { CurrencyString - The local currency string used when converting
  324.   currency values to text. Default value is queried from the system
  325.   at program startup. }
  326.  
  327.   CurrencyString: string[7];
  328.  
  329. { CurrencyFormat - The order of currency value, currency string, and
  330.   separating space used when converting currency values to text.
  331.   Default value is queried from the system at program startup.
  332.  
  333.   The following values four are possible, with the fifth one
  334.   being an additional value that is only supported by OS/2:
  335.  
  336.     0 = '$1'       1 = '1$'       2 = '$ 1'      3 = '1 $'
  337.  
  338.     4 = Currency string replaces decimal indicator }
  339.  
  340.   CurrencyFormat: Byte;
  341.  
  342. { NegCurrFormat - Corresponds to CurrencyFormat, but is used when
  343.   converting negative currency values to text. Queried from the
  344.   system at program startup.
  345.  
  346.   The following values are possible:
  347.  
  348.     0 = '($1)'     1 = '-$1'      2 = '$-1'      3 = '$1-'
  349.     4 = '(1$)'     5 = '-1$'      6 = '1-$'      7 = '1$-'
  350.     8 = '-1 $'     9 = '-$ 1'    10 = '$ 1-'
  351.  
  352.   Since OS/2 doesn't support a special format for negative currency
  353.   values, a format is chosen that matches the CurrencyFormat with
  354.   a preceding '-'. The following list shows the possible values:
  355.  
  356.     CurrencyFormat           NegCurrFormat
  357.  
  358.       0 = '$1'                 1 = -$1
  359.       1 = '1$'                 5 = -1$
  360.       2 = '$ 1'                9 = -$ 1
  361.       3 = '1 $'                8 = -1 $ }
  362.  
  363.   NegCurrFormat: Byte;
  364.  
  365. { ThousandSeparator - The character used to separate blocks of three
  366.   digits when converting floating point values to text. Queried from
  367.   the system at program startup. }
  368.  
  369.  ThousandSeparator: Char;
  370.  
  371.  { DecimalSeparator - The character used to separate the integer part
  372.   from the fractional part when converting floating point values to
  373.   text. Queried from the system at program startup. }
  374.  
  375.   DecimalSeparator: Char;
  376.  
  377. { CurrencyDigits - The number of digits used in the fractional part
  378.   of a currency value when converting a currency value to text.
  379.   Queried from the system at program startup. }
  380.  
  381.   CurrencyDecimals: Byte;
  382.  
  383. { ListSeparator - The character to use when separating items in a list.
  384.   Currently not used by any function. }
  385.  
  386.   ListSeparator: Char;
  387.  
  388. { --- Memory management --- }
  389.  
  390. { AllocMem - Allocates a memory block of the desired size on the heap.
  391.   In contrast to the GetMem standard procedure, AllocMem fills the
  392.   whole block with zeroes. }
  393.  
  394. function AllocMem(Size: Cardinal): Pointer;
  395.  
  396. { ReAllocMem - Re-allocates a previously allocated memory block and
  397.   changes its size. Copies the contents of the old block into the
  398.   new one. CurSize and NewSize specify the current and the new size
  399.   of the block. If the new size is larger than the current size, the
  400.   additional bytes are zeroed. The old memory block is automatically
  401.   disposed. Note that the resulting pointer will always be different
  402.   from the old pointer, even if the size isn't changed. The function
  403.   can handle NIL pointers and zero blocks. }
  404.  
  405. function ReAllocMem(P: Pointer; CurSize, NewSize: Cardinal): Pointer;
  406.  
  407. { --- Exit procedure handling --- }
  408.  
  409. { AddExitProc - Adds a parameterless procedure to the list of
  410.   procedures to be called when the program is terminated. Note that
  411.   the procedure that is added last will be called first. }
  412.  
  413. procedure AddExitProc(Proc: TProcedure);
  414.  
  415. { CallExitProcs - Calls all procedures that were installed by
  416.   AddExitProc and deletes them from the list. Note that the
  417.   procedure that was added last will be called first. }
  418.  
  419. procedure CallExitProcs;
  420.  
  421. { --- String handling --- }
  422.  
  423. { NewStr - Allocates a block of memory on the heap and fills it with
  424.   the given string, returns a PString to the memory block. The memory
  425.   block's size will be exactly one byte more than the string's real
  426.   length. Empty strings don't use any heap space, the function returns
  427.   NullStr in this case. Since NullStr points to EmptyStr, the function
  428.   never returns NIL, so you can always de-reference the resulting
  429.   pointer. Use DisposeStr to free the memory block. }
  430.  
  431. function NewStr(const S: String): PString;
  432.  
  433. { DisposeStr - Disposes a block of memory on the heap that contains
  434.   a string. The block must have been allocated by a call to NewStr.
  435.   If the given pointer is NullStr (and thereby references the empty
  436.   string) or NIL, the function does absolutely nothing. }
  437.  
  438. procedure DisposeStr(P: PString);
  439.  
  440. { AssignStr - Assigns a new value to a string pointer that has been
  441.   previously allocated by a call to NewStr, or is NIL. The old string
  442.   is disposed by DisposeStr, and the new one is allocated by NewStr. }
  443.  
  444. procedure AssignStr(var P: PString; const S: string);
  445.  
  446. { AppendStr - Appends a string to the end of another. }
  447.  
  448. procedure AppendStr(var Dest: string; const S: string);
  449.  
  450. { UpperCase - Converts a string to upper case by simply changing all
  451.   occurences of 'a'..'z' to the corresponding upper case characters.
  452.   If you want a conversion that also considers international special
  453.   characters, use AnsiUpperCase. }
  454.  
  455. function UpperCase(const S: string): string;
  456.  
  457. { LowerCase - Converts a string to lower case by simply changing all
  458.   occurences of 'A'..'Z' to the corresponding lower case characters.
  459.   If you want a conversion that also considers international special
  460.   characters, use AnsiLowerCase. }
  461.  
  462. function LowerCase(const S: string): string;
  463.  
  464. { CompareStr - Compares two strings and returns an integer value
  465.   as in the following table:
  466.  
  467.     S1 < S2       Result < 0
  468.     S1 = S2       Result = 0
  469.     S1 > S2       Result > 0
  470.  
  471.   CompareStr is case-sensitive, but does not take international
  472.   special characters or the currently selected codepage into account. }
  473.  
  474. function CompareStr(const S1, S2: string): Integer;
  475.  
  476. { CompareText - Compares two strings and returns an integer value
  477.   as in the following table:
  478.  
  479.     S1 < S2       Result < 0
  480.     S1 = S2       Result = 0
  481.     S1 > S2       Result > 0
  482.  
  483.   CompareText is case-insensitive, and does not take international
  484.   special characters or the currently selected codepage into account. }
  485.  
  486. function CompareText(const S1, S2: string): Integer;
  487.  
  488. { AnsiUpperCase - Converts a string to upper case. This function
  489.   also takes international special characters and the currently
  490.   selected codepage into account. If you don't want this, use
  491.   UpperCase. }
  492.  
  493. function AnsiUpperCase(const S: string): string;
  494.  
  495. { AnsiLowerCase - Converts a string to lower case. This function
  496.   also takes international special characters and the currently
  497.   selected codepage into account. If you don't want this, use
  498.   LowerCase. Note that AnsiLowerCase is not available under OS/2. }
  499.  
  500. {$ifndef os2}
  501. function AnsiLowerCase(const S: string): string;
  502. {$endif}
  503.  
  504. { AnsiCompareStr - Compares two strings and returns an integer value
  505.   as in the following table:
  506.  
  507.     S1 < S2       Result < 0
  508.     S1 = S2       Result = 0
  509.     S1 > S2       Result > 0
  510.  
  511.   AnsiCompareStr is case-sensitive, and takes international special
  512.   characters and the currently selected codepage into account. Note
  513.   that the function is not available under OS/2. }
  514.  
  515. {$ifndef OS2}
  516. function AnsiCompareStr(const S1, S2: string): Integer;
  517. {$endif}
  518.  
  519. { AnsiCompareText - Compares two strings and returns an integer value
  520.   as in the following table:
  521.  
  522.     S1 < S2       Result < 0
  523.     S1 = S2       Result = 0
  524.     S1 > S2       Result > 0
  525.  
  526.   AnsiCompareText is case-insensitive, and takes international special
  527.   characters and the currently selected codepage into account. }
  528.  
  529. function AnsiCompareText(const S1, S2: string): Integer;
  530.  
  531. { Trim - Removes leading and trailing spaces and control characters. }
  532.  
  533. function Trim(const S: string): string;
  534.  
  535. { TrimLeft - Removes leading spaces and control characters. }
  536.  
  537. function TrimLeft(const S: string): string;
  538.  
  539. { TrimRight - Removes trailing spaces and control characters. }
  540.  
  541. function TrimRight(const S: string): string;
  542.  
  543. { QuotedStr - Returns the given string enclosed in quotes. Quotes already
  544.   included in the string are returned as two quote characters. }
  545.  
  546. function QuotedStr(const S: string): string;
  547.  
  548. { IsValidIdent - Checks whether the given string contains a legal
  549.   Pascal identifier. Check your Speed-Pascal manual to see what a
  550.   legal identifier looks like. :-) }
  551.  
  552. function IsValidIdent(const Ident: string): Boolean;
  553.  
  554. { IntToStr - Converts an integer value to a string of digits. }
  555.  
  556. function IntToStr(Value: LongInt): string;
  557.  
  558. { IntToHex - Converts an integer value to a string of hexadecimal
  559.   digits. The minimum desired number of digits can be specified.
  560.   If the result contains less digits, it is left-padded with zeroes. }
  561.  
  562. function IntToHex(Value: LongInt; Digits: Integer): string;
  563.  
  564. { StrToInt - Extracts an integer value from a string. If the string
  565.   doesn't contain a legal integer value, exception EConvertError
  566.   is raised. }
  567.  
  568. function StrToInt(const S: string): LongInt;
  569.  
  570. { StrToIntDef - Extracts an integer value from a string. If the string
  571.   doesn't contain a legal integer value, the desired default value
  572.   is returned instead. }
  573.  
  574. {$ifdef GUI}
  575. function StrToIntDef(const S: string; Default: LongInt): LongInt;
  576. {$endif GUI}
  577.  
  578. { LoadStr - Loads a string from the application's resources. The
  579.   string is retrieved by an integer number. If the resources don't
  580.   contain a string with the given number, LoadStr returns an empty
  581.   string. }
  582.  
  583. {$ifdef GUI}
  584. function LoadStr(Ident: Word): string;
  585. {$endif GUI}
  586.  
  587. { LoadNLSStr - Loads a string from the application's current language table. The
  588.   string is retrieved by an integer number. If the resources don't
  589.   contain a string with the given number, LoadStr returns an empty
  590.   string. }
  591.  
  592. function LoadNLSStr(Ident: Word): string;
  593.  
  594. { LoadTableStr - Loads a string from the specified string table. The
  595.   string is retrieved by an integer number. If the resources don't
  596.   contain a string with the given number, LoadStr returns an empty
  597.   string. }
  598.  
  599. function LoadTableStr(const Table:string;Ident: Word): string;
  600.  
  601. { FmtLoadStr - Loads a string from the application's resources and
  602.   replaces some placeholders by values given in an open-array. The
  603.   string is retrieved by an integer number. If the resources don't
  604.   contain a string with the given number, FmtLoadStr returns an
  605.   empty string. }
  606.  
  607. {$ifdef GUI}
  608. function FmtLoadStr(Ident: Word; const Args: array of const): string;
  609. {$endif GUI}
  610.  
  611. { FmtLoadNLSStr - Loads a string from the application's current language table and
  612.   replaces some placeholders by values given in an open-array. The
  613.   string is retrieved by an integer number. If the resources don't
  614.   contain a string with the given number, FmtLoadStr returns an
  615.   empty string. }
  616.  
  617. function FmtLoadNLSStr(Ident: Word; const Args: array of const): string;
  618.  
  619. { FmtLoadTableStr - Loads a string from the specified string table and
  620.   replaces some placeholders by values given in an open-array. The
  621.   string is retrieved by an integer number. If the resources don't
  622.   contain a string with the given number, FmtLoadStr returns an
  623.   empty string. }
  624.  
  625. function FmtLoadTableStr(const Table:string;Ident: Word; const Args: array of const): string;
  626.  
  627.  
  628. { SysErrorMessage - Returns a system error message. }
  629.  
  630. {$ifdef OS2}
  631. function SysErrorMessage(MsgNum: LongInt): string;
  632. {$endif OS2}
  633.  
  634. { --- File management --- }
  635.  
  636. { FileOpen - Opens an existing file with a given file mode. The file
  637.   mode is a logical combination of one of the file open constants
  638.   (fmOpenXXX) and one of the sharing mode constants (fmShareXXX). If
  639.   the file is successfully opended, the resulting integer value is
  640.   positive and contains the file handle. Otherwise the result is the
  641.   negative value of the error code returned by the operating system. }
  642.  
  643. function FileOpen(const FileName: string; Mode: Word): LongInt;
  644.  
  645. { FileCreate - Creates a new file or overwrites an existing one. No
  646.   file mode can be specified, so the file is always created with
  647.   fmOpenWrite or fmShareExclusive. If the file is successfully
  648.   created, the resulting integer value is positive and contains the
  649.   file handle. Otherwiese the result is the negative value of the
  650.   error code returned by the operating system. }
  651.  
  652. function FileCreate(const FileName: string): LongInt;
  653.  
  654. { FileOpenOrCreate - Opens or creates a file, depending on whether
  655.   the file already exists or not. A file mode can be specified. The
  656.   file mode is a logical combination of one of the file open constants
  657.   (fmOpenXXX) and one of the sharing mode constants (fmShareXXX). If
  658.   the file is successfully opended or created, the resulting integer
  659.   value is positive and contains the file handle. Otherwise the
  660.   result is the negative value of the error code returned by the
  661.   operating system. }
  662.  
  663. function FileOpenOrCreate(const FileName: string; Mode: Word): LongInt;
  664.  
  665. { FileCreateIfNew - Creates a file if there's not already a file with
  666.   the same name. A file mode can be specified. The file mode is a
  667.   logical combination of one of the file open constants (fmOpenXXX)
  668.   and one of the sharing mode constants (fmShareXXX). If the new file
  669.   is successfully created, the resulting integer value is positive and
  670.   contains the file handle. Otherwise the result is the negative value
  671.   of the error code returned by the operating system. Note that this
  672.   function also fails if the file already exists. }
  673.  
  674. function FileCreateIfNew(const FileName: string; Mode: Word): LongInt;
  675.  
  676. { FileRead - Attempts to read up to Count bytes from the given file
  677.   handle and returns the number of bytes actually read. If an error
  678.   occurs, the result is -1. }
  679.  
  680. function FileRead(Handle: LongInt; var Buffer; Count: Longint): Longint;
  681.  
  682. { FileWrite - Attempts to write up to Count bytes to the given file
  683.   handle and returns the number of bytes actually written. If an error
  684.   occurs, the result is -1. }
  685.  
  686. function FileWrite(Handle: LongInt; const Buffer; Count: LongInt): LongInt;
  687.  
  688. { FileSeek - Changes the current position of a file handle by Count
  689.   bytes. The actual movement depends on the value of Origin, according
  690.   to the following table:
  691.  
  692.     Origin        Action
  693.  
  694.       0           Move relative to the file's beginning
  695.       1           Move relative to the current position
  696.       2           Move relative to the file's end
  697.  
  698.   The function returns the new position, or -1 if an error occured. }
  699.  
  700. function FileSeek(Handle: LongInt; Offset: LongInt; Origin: Integer): LongInt;
  701.  
  702. { FileClose - Closes a file and frees the handle. }
  703.  
  704. procedure FileClose(Handle: LongInt);
  705.  
  706. { FileLock - Locks a range of a file for exclusive access by the
  707.   application. Returns a Boolean value indicating success or
  708.   failure. Note that the function waits up to the time specified
  709.   in the LockTimeout global variable before it fails. }
  710.  
  711. function FileLock(Handle, Offset, Range: LongInt): Boolean;
  712.  
  713. { FileUnLock - Unlocks a range of a file that was previously locked
  714.   for exclusive access by the application. Returns a Boolean value
  715.   indicating success or failure. }
  716.  
  717. function FileUnlock(Handle, Offset, Range: LongInt): Boolean;
  718.  
  719. { FileAge - Returns the date and time of a file's last modification.
  720.  
  721.   If the file doesn't exist, -1 is returned instead.
  722.  
  723.   To use date / time formatting functions for this value, convert it
  724.   to a TDateTime by a call to FileDateToDateTime first. }
  725.  
  726. function FileAge(const FileName: string): Longint;
  727.  
  728. { FileExists - Indicates whether a file exists or not. }
  729.  
  730. function FileExists(const FileName: string): Boolean;
  731.  
  732. { FindFirst - Starts a search for files specified by a name pattern
  733.   and file attributes.
  734.  
  735.   Any pattern that is allowed on the command line is also a legal
  736.   argument for Path.
  737.  
  738.   Attr is a logical combination of file attributes (faXXX) and
  739.   file-must attributes (faMustXXX), the latter being available only
  740.   under OS/2.
  741.  
  742.   The var SearchRec will contain name and attributes of the first file
  743.   that matched the given specs. In this case the function returns 0.
  744.   If an error occurs, the result is the negative value of the error
  745.   code returned by the operating system.
  746.  
  747.   Use FindNext to find more files and FindClose to end the file
  748.   search. Note that you must use FindClose, or you may run out of
  749.   handles after a while. }
  750.  
  751. function FindFirst(const Path: string; Attr: Integer; var SearchRec: TSearchRec): LongInt;
  752.  
  753. { FindNext - After a call to FindNext, the var SearchRec contains the
  754.   next file that matches the specs of a file search previously started
  755.   by FindFirst.
  756.  
  757.   A return value of 0 indicates success. You may call FindNext until
  758.   an error occures (with the negative value of the operating system's
  759.   error code returned), or until no more matching files are found
  760.   (usually indicated by a return value of -18.) }
  761.  
  762. function FindNext(var SearchRec: TSearchRec): LongInt;
  763.  
  764. { FindClose - Ends a file search previously started by FindFirst. Note
  765.   that you must use FindClose, or you may run out of handles after a
  766.   while. }
  767.  
  768. procedure FindClose(var SearchRec: TSearchRec);
  769.  
  770. { FileGetDate - Returns the date and time of a file's last
  771.   modification. If the given file handle is invalid, -1 is returned
  772.   instead.
  773.  
  774.   To use date / time formatting functions for the result, convert
  775.   it to a TDateTime by a call to FileDateToDateTime first. }
  776.  
  777. function FileGetDate(Handle: LongInt): Longint;
  778.  
  779. { FileSetDate - Changes the date and time of a file's last
  780.   modification. If the operation fails due to an invalid handle or
  781.   an illegal Age parameter, the date and time remain unchanged.
  782.  
  783.   This procedure doesn't accept TDateTime values. You have to convert
  784.   them to a LongInt by DateTimeToFileDate first. }
  785.  
  786. procedure FileSetDate(Handle: Integer; Age: Longint);
  787.  
  788. { FileGetAttr - Returns a file's attributes. The result value is a
  789.   logical combination of file attribute constants (faXXX). If the
  790.   function fails due to a non-existing file or another error
  791.   condition, the result is the negative value of the operating
  792.   system's error code. }
  793.  
  794. function FileGetAttr(const FileName: string): LongInt;
  795.  
  796. { FileSetAttr - Changes a file's attributes. The Attr parameter may
  797.   contain any logical combination of file attribute constants
  798.   (faXXX). A result value of 0 indicates success. If the function
  799.   fails due to a non-existing file or another error condition, the
  800.   result is the negative value of the operating system's error code. }
  801.  
  802. function FileSetAttr(const FileName: string; Attr: Integer): Integer;
  803.  
  804. { CopyFile - Copies a file. Result is a Boolean indicating success or
  805.   failure. }
  806.  
  807. function CopyFile(const SourceName, DestName: string): Boolean;
  808.  
  809. { DeleteFile - Deletes a file. Result is a Boolean indicating success
  810.   or failure. }
  811.  
  812. function DeleteFile(const FileName: string): Boolean;
  813.  
  814. { RenameFile - Renames a file. Result is a Boolean indicating success
  815.   or failure. You may use RenameFile to move a file to a new location,
  816.   but only if the drive stays the same. }
  817.  
  818. function RenameFile(const OldName, NewName: string): Boolean;
  819.  
  820. { ChangeFileExt - Changes the extension of a given filename. The
  821.   extension is the part from the rightmost dot to the end of the
  822.   filename. If the old filename doesn't contain an extension, it
  823.   is simply added. The extension must start with a dot.
  824.  
  825.   Note that the function only handles a string, but does not perform
  826.   any physical changes to files. }
  827.  
  828. function ChangeFileExt(const FileName, Extension: string): string;
  829.  
  830. { ExtractFilePath - Returns the drive and directory parts of a
  831.   filename, that is, everything from the start to the rightmost colon
  832.   or backslash in the string. If the filename doesn't contain drive or
  833.   directory information, an empty string is returned. }
  834.  
  835. function ExtractFilePath(const FileName: string): string;
  836.  
  837. { ExtractFileName - Returns the name and extension parts of a
  838.   filename, that is, everything from rightmost colon or backslash to
  839.   the end of the string. If the filename doesn't contain a name or
  840.   extension, an empty string is returned. }
  841.  
  842. function ExtractFileName(const FileName: string): string;
  843.  
  844. { ExtractFileExt - Returns the extension part of a filename, that is,
  845.   everything from rightmost dot to the end of the string. If the
  846.   filename doesn't contain a dot, an empty string is returned. }
  847.  
  848. function ExtractFileExt(const FileName: string): string;
  849.  
  850. { ConcatFileName - Concatenates two filenames, assuming the first
  851.   one specifies some kind of directory information, and the second
  852.   one a filename. The result is a complete legal pathname. The
  853.   function automatically inserts a backslash, if necessary. }
  854.  
  855. function ConcatFileName(const PathName, FileName: string): string;
  856.  
  857. { ExpandFileName - Expands a filename to an absolute filename, that
  858.   is, a filename containing a drive letter, directory information
  859.   relative to the root of the drive, and the filename. Embedded '..'
  860.   are removed. }
  861.  
  862. function ExpandFileName(FileName: string): string;
  863.  
  864. { EditFileName - Changes a filename using a pattern possibly
  865.   containing the wildcards '*' and '?'. Everything that would
  866.   be accepted by the COPY command should be legal for Name and
  867.   Edit. }
  868.  
  869. function EditFileName(const Name, Edit: string): string;
  870.  
  871. { FileSearch - Searches for a file Name in a list of directories
  872.   given by DirList. The directory entries must be separated by
  873.   semicolons, just like the system's PATH. The working directory
  874.   is implicitly prepended to the list of directories. The result
  875.   string is either the first occurence of the file complete with
  876.   the directory it was found in, or the empty string, if the file
  877.   could not be found. }
  878.  
  879. function FileSearch(const Name, DirList: string): string;
  880.  
  881. { DiskFree - Returns the free space of the given disk drive. Drive 0
  882.   is the current drive, Drive 1 is 'A:', and so on. If the given drive
  883.   is invalid or cannot be read, -1 is returned, otherwise the result
  884.   contains the number of bytes free. }
  885.  
  886. function DiskFree(Drive: Byte): Longint;
  887.  
  888. { DiskSize - Returns the disk size of the given disk drive. Drive 0
  889.   is the current drive, Drive 1 is 'A:', and so on. If the given drive
  890.   is invalid or cannot be read, -1 is returned, otherwise the result
  891.   contains the number of bytes that can be potentially used for file
  892.   storage. }
  893.  
  894. function DiskSize(Drive: Byte): Longint;
  895.  
  896. { FileDateToDateTime - Converts a file date / time value to a
  897.   TDateTime that can be used within formatting operations. }
  898.  
  899. function FileDateToDateTime(FileDate: Longint): TDateTime;
  900.  
  901. { FileDateToDateTime - Converts a TDateTime to a file date / time
  902.   value that can be used within file functions. }
  903.  
  904. function DateTimeToFileDate(DateTime: TDateTime): Longint;
  905.  
  906. { --- 'C'-like string handling --- }
  907.  
  908. { StrLen - Returns the length of Str, ignoring the terminating zero. }
  909.  
  910. function StrLen(Str: PChar): Cardinal;
  911.  
  912. { StrEnd - Returns a pointer to the terminating zero of Str. }
  913.  
  914. function StrEnd(Str: PChar): PChar;
  915.  
  916. { StrMove - Copies exactly Count characters from Source to Dest. It's
  917.   okay when Source and Dest overlap, StrMove can handle this. }
  918.  
  919. function StrMove(Dest, Source: PChar; Count: Cardinal): PChar;
  920.  
  921. { StrCopy - Copies Source to Dest and returns Dest. }
  922.  
  923. function StrCopy(Dest, Source: PChar): PChar;
  924.  
  925. { StrECopy - Copies Source to Dest and returns a pointer to the
  926.   terminating zero of the resulting string. }
  927.  
  928. function StrECopy(Dest, Source: PChar): PChar;
  929.  
  930. { StrLCopy - Copies a maximum of MaxLen characters from Source to Dest
  931.   and returns Dest. }
  932.  
  933. function StrLCopy(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  934.  
  935. { StrPCopy - Copies a Pascal string Source to a PChar Dest and returns
  936.   Dest. }
  937.  
  938. function StrPCopy(Dest: PChar; const Source: String): PChar;
  939.  
  940. { StrPLCopy - Copies a maximum of MaxLen characters from a Pascal
  941.   string Source to a PChar Dest. Returns Dest. }
  942.  
  943. function StrPLCopy(Dest: PChar; const Source: string; MaxLen: Cardinal): PChar;
  944.  
  945. { StrCat - Concatenates Dest and Source, that is, appends Source to
  946.   the end of Dest, and returns Dest. }
  947.  
  948. function StrCat(Dest, Source: PChar): PChar;
  949.  
  950. { StrLCat - Concatenates Dest and Source, that is, appends Source to
  951.   the end of Dest, but copies only so many characters that the
  952.   resulting string does not exceed MaxLen characters. Returns Dest. }
  953.  
  954. function StrLCat(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  955.  
  956. { StrComp - Compares two strings and returns an integer value
  957.   as in the following table:
  958.  
  959.     Str1 < Str2       Result < 0
  960.     Str1 = Str2       Result = 0
  961.     Str1 > Str2       Result > 0
  962.  
  963.   StrComp is case-sensitive, but does not take international special
  964.   characters or the currently selected codepage into account. }
  965.  
  966. function StrComp(Str1, Str2: PChar): Integer;
  967.  
  968. { StrIComp - Compares two strings and returns an integer value
  969.   as in the following table:
  970.  
  971.     Str1 < Str2       Result < 0
  972.     Str1 = Str2       Result = 0
  973.     Str1 > Str2       Result > 0
  974.  
  975.   StrComp is case-insensitive, and does not take international
  976.   special characters or the currently selected codepage into account. }
  977.  
  978. function StrIComp(Str1, Str2: PChar): Integer;
  979.  
  980. { StrLComp - Compares up to MaxLen characters of two strings and
  981.   returns an integer value as in the following table:
  982.  
  983.     Str1 < Str2       Result < 0
  984.     Str1 = Str2       Result = 0
  985.     Str1 > Str2       Result > 0
  986.  
  987.   StrLComp is case-sensitive, but does not take international special
  988.   characters or the currently selected codepage into account. }
  989.  
  990. function StrLComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  991.  
  992. { StrLIComp - Compares up to MaxLen characters of two strings and
  993.   returns an integer value as in the following table:
  994.  
  995.     Str1 < Str2       Result < 0
  996.     Str1 = Str2       Result = 0
  997.     Str1 > Str2       Result > 0
  998.  
  999.   StrLComp is case-insensitive, and does not take international
  1000.   special characters or the currently selected codepage into account. }
  1001.  
  1002. function StrLIComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  1003.  
  1004. { StrScan - Searches for the first occurence of a character in a
  1005.   string. Returns the pointer to the occurence, or NIL, if the
  1006.   character cannot be found. }
  1007.  
  1008. function StrScan(Str: PChar; Chr: Char): PChar;
  1009.  
  1010. { StrRScan - Searches for the last occurence of a character in a
  1011.   string. Returns the pointer to the occurence, or NIL, if the
  1012.   character cannot be found. }
  1013.  
  1014. function StrRScan(Str: PChar; Chr: Char): PChar;
  1015.  
  1016. { StrScan - Searches for the first occurence of a SubStr in a given
  1017.   string Str. Returns the pointer to the occurence, or NIL, if the
  1018.   SubStr cannot be found. }
  1019.  
  1020. function StrPos(Str, SubStr: PChar): PChar;
  1021.  
  1022. { StrUpper - Converts a string to upper case by simply changing all
  1023.   occurences of 'a'..'z' to the corresponding upper case characters.
  1024.   Returns a pointer to the string. Changes the source string, does
  1025.   not create a new string. Does also not take international special
  1026.   characters or the currently selected codepage into account. }
  1027.  
  1028. function StrUpper(Str: PChar): PChar;
  1029.  
  1030. { StrLower - Converts a string to lower case by simply changing all
  1031.   occurences of 'A'..'Z' to the corresponding lower case characters.
  1032.   Returns a pointer to the string.  Changes the source string, does
  1033.   not create a new string. Does also not take international special
  1034.   characters or the currently selected codepage into account. }
  1035.  
  1036. function StrLower(Str: PChar): PChar;
  1037.  
  1038. { StrPas - Converts a PChar Str to a Pascal string. }
  1039.  
  1040. function StrPas(Str: PChar): String;
  1041.  
  1042. { StrAlloc - Allocates a block of memory for storing PChars. The size
  1043.   is specified and stored in a double word that preceeds the buffer.
  1044.   Use StrDispose to free the buffer. }
  1045.  
  1046. function StrAlloc(Size: Cardinal): PChar;
  1047.  
  1048. { StrBufSize - Returns the size of a PChar buffer that has been
  1049.   previously allocated by StrAlloc. }
  1050.  
  1051. function StrBufSize(Str: PChar): Cardinal;
  1052.  
  1053. { StrNew - Creates a copy of a given string. In contrast to StrCopy,
  1054.   StrNew allocates a memory block that can hold the string, by a
  1055.   call to StrAlloc. Then it copies the source string. The new
  1056.   string can be disposed by a call to StrDispose. }
  1057.  
  1058. function StrNew(Str: PChar): PChar;
  1059.  
  1060. { StrDispose - Disposes a PChar buffer that has been previously
  1061.   allocated by a call to StrAlloc. }
  1062.  
  1063. procedure StrDispose(Str: PChar);
  1064.  
  1065. { --- String formatting --- }
  1066.  
  1067. { Format - Formats a string and replaces placeholders by arguments.
  1068.  
  1069.   The format string can contain arbitrary text. This text is simply
  1070.   copied into the result. Everything that starts with a '%' is
  1071.   considered a placeholder. Placeholders are replaced by the
  1072.   parameters given in the variant-type open-array Args. The first
  1073.   placeholder is replaced by the first argument, the second one
  1074.   by the second argument, and so on. You must specify at least as many
  1075.   parameters as there are placeholders, otherwise an exception
  1076.   EConvertError will be raised.
  1077.  
  1078.   The way a placeholder / argument pair will be handled is controlled
  1079.   by some optional specifiers. The line below shows the possibilities.
  1080.  
  1081.   Text in " " must appear literally, 'index', 'width' and 'precision'
  1082.   must be replaced by integer numbers, and 'type' must be replaced by
  1083.   a character that specifies the argument type.
  1084.  
  1085.   Parts enclosed in angular brackets are optional, the angular
  1086.   brackets must not appear in the format specifier, they are only used
  1087.   to show the syntax.
  1088.  
  1089.     "%" [index ":"] ["-"] [width] ["." precision] type
  1090.  
  1091.   The different parts of the format specifier must appear in the
  1092.   given order, and they have the following meaning:
  1093.  
  1094.     "%"                Begins the format specifier
  1095.  
  1096.     index ":"          Takes the next argument from the array entry
  1097.                        given by Integer value index. Normally the
  1098.                        arguments are used one after the other. This
  1099.                        part of the format specifier allows to change
  1100.                        this behaviour.
  1101.  
  1102.     "-"                Left-Justifies the text inserted for the format
  1103.                        specifier. Normally the text is justified to
  1104.                        the right. Only applies if the string is left-
  1105.                        padded with spaces by the width-specifier.
  1106.  
  1107.     width              Integer value that specifies the width being
  1108.                        reserved for the argument. If the string
  1109.                        resulting from the conversion of the argument
  1110.                        contains less than width characters, it is
  1111.                        left padded with spaces to achieve this minimum
  1112.                        length. If "-" is used to activate left-
  1113.                        justification, the string is padded to the
  1114.                        right rather than to the left. If the string
  1115.                        already has a length equal to or greater than
  1116.                        width, no padding is needed.
  1117.  
  1118.     "." precision      Integer value that specifies the precision
  1119.                        used when converting the argument. The actual
  1120.                        consequences of precision depend on the
  1121.                        argument type. See descriptions below for
  1122.                        details.
  1123.  
  1124.   The index, width, and precision specifiers can also contain an
  1125.   asterisk ('*'). In this case, the real value is taken from the
  1126.   next argument array entry, which has to be an integer value, or
  1127.   EConvertError will be raised.
  1128.  
  1129.   Following are the characters allowed to specify the argument type.
  1130.   Note that 'decimal point' and 'thousand separator' mean that the
  1131.   characters contained in the global variables DecimalSeparator and
  1132.   ThousandSeparator will be inserted.
  1133.  
  1134.     d                  Decimal format. The corresponding argument must
  1135.                        be an integer value, otherwise EConvertError is
  1136.                        raised. The argument is converted to a decimal
  1137.                        string. If a precision is specified, the string
  1138.                        is guaranteed to have at least a number of
  1139.                        digits equal to precision. If the string is
  1140.                        shorter, it is padded with zeroes.
  1141.  
  1142.     e                  Scientific (exponential) format. The
  1143.                        corresponding argument must be a floating point
  1144.                        value, otherwise EConvertError is raised. The
  1145.                        argument is converted to a decimal string using
  1146.                        scientific notation. The string starts with a
  1147.                        minus sign, if the argument is negative. One
  1148.                        digit always precedes the decimal point. The
  1149.                        number of digits following the decimal point is
  1150.                        controlled by the optional precision specifier.
  1151.                        The total number of digits is always equal to
  1152.                        precision. If precision is not specified, a
  1153.                        default of 15 is assumed, resulting in 1 digit
  1154.                        before and 14 after the decimal point.
  1155.                        Following is the exponential 'E' with a plus or
  1156.                        a minus sign and up to 3 digits indicating the
  1157.                        exponent.
  1158.  
  1159.     f                  Fixed point format. The corresponding argument
  1160.                        must be a floating point value, otherwise
  1161.                        EConvertError is raised. The argument is
  1162.                        converted to a string using fixed notation. It
  1163.                        starts with a minus sign, if the argument is
  1164.                        negative. All digits of the argument's integer
  1165.                        part appear in the result. Following is a
  1166.                        decimal separator and a number of digits equal
  1167.                        to precision. If no precision is specified, a
  1168.                        default of 2 decimal places is assumed.
  1169.  
  1170.     g                  General number format. The argument must be a
  1171.                        floating point value, otherwise EConvertError
  1172.                        is raised. The argument is converted to a
  1173.                        string using either fixed or scientific format,
  1174.                        depending on which results in a shorter string.
  1175.                        The optional precision specifier controls the
  1176.                        number of significant digits (used for
  1177.                        rounding) with a default of 15. The result will
  1178.                        contain neither unnecessary zeroes nor an
  1179.                        unnecessary decimal point. If the argument
  1180.                        value is greater than or equal to 0.00001, and
  1181.                        if the number of digits to the left of the
  1182.                        decimal point is less than or equal to the
  1183.                        precision, fixed format is used. Otherwise the
  1184.                        result uses scientific format.
  1185.  
  1186.     m                  Currency (money) format. The corresponding
  1187.                        argument must be a floating point value,
  1188.                        otherwise EConvertError is raised. The argument
  1189.                        is converted to a string using the following
  1190.                        global variables:
  1191.  
  1192.                          CurrencyString
  1193.                          CurrencyFormat
  1194.                          NegCurrFormat
  1195.                          CurrencyDecimals
  1196.  
  1197.                        If a precision is specified, it overrides the
  1198.                        default value of CurrencyDecimals.
  1199.  
  1200.     n                  Number format. Equal to fixed, but the result
  1201.                        string will contain thousand separators.
  1202.  
  1203.     p                  Pointer format. The corresponding argument must
  1204.                        be a pointer value, otherwise EConvertError is
  1205.                        raised. The value is converted to a string
  1206.                        containing the hexadecimal representation of
  1207.                        the pointer, with an additional ':' in the
  1208.                        middle. The resulting string has always a
  1209.                        length of 9 characters. Since we are dealing
  1210.                        with flat memory model, we have a full 32-bit
  1211.                        pointer with no segment part, only offset.
  1212.  
  1213.     s                  String format. The corresponding argument must
  1214.                        be a single character, a string or a PChar value,
  1215.                        otherwise EConvertError is raised. The argument
  1216.                        is simply copied to the destination string. If
  1217.                        a precision is specified, it is considered the
  1218.                        maximum length of the argument string. Longer
  1219.                        strings will be truncated.
  1220.  
  1221.     x                  Hexadecimal format. The corresponding argument
  1222.                        must be an integer value, otherwise EConvertError
  1223.                        is raised. The argument is converted to a
  1224.                        hexadecimal string. If a precision is specified,
  1225.                        the string is guaranteed to have at least a
  1226.                        number of digits equal to precision. If the
  1227.                        string is shorter, it is padded with zeroes. }
  1228.  
  1229. function Format(const Format: string; const Args: array of const): string;
  1230.  
  1231. { FmtStr - Formats a string and replaces placeholders by arguments.
  1232.   See Format for a detailed description of the format string and the
  1233.   argument array. }
  1234.  
  1235. procedure FmtStr(var Result: string; const Format: string;
  1236.   const Args: array of const);
  1237.  
  1238. { StrFmt - Formats a string and replaces placeholders by arguments.
  1239.   Note that the Buffer must be large enough to hold the complete
  1240.   result, otherwise a protection fault (EGPFault) may occur. See
  1241.   Format for a detailed description of the format string and the
  1242.   argument array. }
  1243.  
  1244. function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar;
  1245.  
  1246. { StrLFmt - Formats a string and replaces placeholders by arguments.
  1247.   The function ensures that the size of the output string written into
  1248.   Buffer won't exceed MaxLen characters. The function's result is also
  1249.   a pointer to Buffer. See Format for a detailed description of the
  1250.   format string and the argument array. }
  1251.  
  1252. function StrLFmt(Buffer: PChar; MaxLen: Cardinal; Format: PChar;
  1253.   const Args: array of const): PChar;
  1254.  
  1255. { FormatBuf - Formats a string and replaces placeholders by arguments.
  1256.   Format and Buffer strings are given as untyped var / const
  1257.   parameters. Their sizes are given in BufLen and FmtLen. The function
  1258.   ensures that the size of the output string written into Buffer won't
  1259.   exceed BufLen characters. The result value is the number of
  1260.   characters actually written into Buffer. See Format for a detailed
  1261.   description of the format string and the argument array. }
  1262.  
  1263. function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
  1264.   FmtLen: Cardinal; const Args: array of const): Cardinal;
  1265.  
  1266. { --- Floating point conversion --- }
  1267.  
  1268. { FloatToStrF - Converts a floating point number to a string. The
  1269.   appearance of the result string can be controlled by specifying
  1270.   a basic format to apply, a precision, and a number of digits.
  1271.   The precision parameter should be less than or equal to 18. The
  1272.   meaning of the digits parameter depends on the format chosen.
  1273.  
  1274.   Following is a detailed description of the possible formats:
  1275.  
  1276.     ffCurrency     Money (currency) format. The argument is converted
  1277.                    to a string using the following global variables:
  1278.  
  1279.                      CurrencyString
  1280.                      CurrencyFormat
  1281.                      NegCurrFormat
  1282.  
  1283.                    The Digits parameter specifies the number of digits
  1284.                    following the decimal point (0 to 18 being legal
  1285.                    values).
  1286.  
  1287.     ffExponent     Scientific (exponential) format. The argument is
  1288.                    converted to a decimal string using scientific
  1289.                    notation. The string starts with a minus sign, if
  1290.                    the argument is negative. One digit precedes the
  1291.                    decimal point. The number of digits following the
  1292.                    decimal point is controlled by Precision. The total
  1293.                    number of digits is always equal to Precision.
  1294.                    Following is the exponential 'E' with a plus or a
  1295.                    minus sign and the exponent with a minimum length
  1296.                    of Digits characters (0 to 4 being legal values).
  1297.  
  1298.     ffFixed        Fixed point format. The argument is converted to a
  1299.                    string using fixed point notation. It starts with a
  1300.                    minus sign, if the argument is negative. All digits
  1301.                    of the argument's integer part appear in the result.
  1302.                    Following is a comma and a number of decimal digits
  1303.                    equal to Digits (0 to 18 being legal values). If
  1304.                    the number of digits to the left of the decimal
  1305.                    point is greater than Precision, the output will be
  1306.                    in scientific format.
  1307.  
  1308.     ffGeneral      General number format. The argument is converted
  1309.                    to a string using either fixed or scientific
  1310.                    format, depending on which results in a shorter
  1311.                    string. The result will contain neither trailing
  1312.                    zeroes nor an unnecessary decimal point. If the
  1313.                    argument value is greater than or equal to 0.00001,
  1314.                    and if the number of digits to the left of the
  1315.                    decimal point is less than or equal to Precision,
  1316.                    fixed format is used. Otherwise the result is
  1317.                    formatted in scientific format with Digits
  1318.                    specifying the minimum number of digits in the
  1319.                    exponent (0 to 4 being legal values).
  1320.  
  1321.     ffNumber       Number format. Equal to fixed, but the result
  1322.                    string will contain thousand separators.
  1323.  
  1324.   If the value is not-a-number, positive infinity, or negative
  1325.   infinity, then the output string will also be NAN, INF, or -INF. }
  1326.  
  1327. function FloatToStrF(Value: Extended; Format: TFloatFormat;
  1328.   Precision, Digits: Integer): string;
  1329.  
  1330. { FloatToStr - Converts a floating point value to a string using
  1331.   general number format and 15 significant digits. See FloatToStrF
  1332.   for more details. }
  1333.  
  1334. function FloatToStr(Value: Extended): string;
  1335.  
  1336. { FloatToText - Converts a floating point number to a string. The
  1337.   result is written to Buffer without a zero teminator being
  1338.   appended. The caller has to ensure that the buffer is large
  1339.   enough to hold the result. The result can be controlled using
  1340.   Format, Precision and Digits parameters. See FloatToStrF for
  1341.   a detailed description of these parameters. }
  1342.  
  1343. function FloatToText(Buffer: PChar; Value: Extended; Format: TFloatFormat;
  1344.   Precision, Digits: Integer): Integer;
  1345.  
  1346. { FormatFloat - Converts a floating point value to a string using a
  1347.   specified format.
  1348.  
  1349.   The parameter Format controls the appearance of the result string.
  1350.  
  1351.   Format can contain up to three sections, separated from each other
  1352.   by semicolons. The first section holds the format string used for
  1353.   positive values, the second one holds the format for negative
  1354.   values, and the third one is applied to zero values. If one of
  1355.   the sections is missing or empty, the first section is used
  1356.   instead. If all sections are missing or empty, general number
  1357.   format is used with a precision of 15. See FloatToStrF for more
  1358.   details about general number format.
  1359.  
  1360.   Each of the three sections can contain arbitrary text, which is
  1361.   simply copied to the result string. Some characters have a special
  1362.   meaning, they serve as placeholders for inserting data from the
  1363.   value parameter.
  1364.  
  1365.   The following list shows all placeholders and their meaning:
  1366.  
  1367.     0         Mandatory digit. If the value has a digit at this
  1368.               position, it is copied to the result. Otherwise a
  1369.               0 is inserted.
  1370.  
  1371.     #         Optional digit. If the value has a digit at this
  1372.               position, it is copied to the result. Otherwise
  1373.               this position of the format string will be ignored.
  1374.  
  1375.     .         Decimal separator. The first occurence of '.' in the
  1376.               format string determines the position at which a decimal
  1377.               separator will be inserted. The decimal separator is
  1378.               taken from the global variable DecimalSeparator. Further
  1379.               occurences of '.' will be ignored.
  1380.  
  1381.     ,         Thousand separator. Any occurence of ',' activates the
  1382.               insertion of thousand separators into the result, where
  1383.               necessary. The thousand separator is taken from the
  1384.               global variable DecimalSeparator.
  1385.  
  1386.     E+ E-     Scientific (exponential) format. If any of the four
  1387.     e+ e-     strings to the left occur in the format string, the
  1388.               result will be formatted using scientific notation.
  1389.               The exponential E will have the same case as in the
  1390.               format string. The exponent itself will always be
  1391.               preceded by its sign, if E+ or e+ are used. E- and e-
  1392.               contain a sign only if the exponent value is negative.
  1393.               Up to four digit placeholders can be used to specify the
  1394.               minimum number of digits used for the exponent.
  1395.  
  1396.     '...'     Characters enclosed in single or double quotes will
  1397.     "..."     simply be copied to the result (without quotes).
  1398.  
  1399.   The floating point value is rounded with a precision equal to the
  1400.   total number of digit placeholders in the format string. Optional
  1401.   digit placeholders between the leftmost and rightmost mandatory
  1402.   digit placeholders will be taken as mandatory digits, so it makes
  1403.   no sense to specify one ore more '#' between zeroes. If the rounded
  1404.   value contains more digits in the integer part than there are
  1405.   placeholders left of the decimal separator, the additional digits
  1406.   will be inserted before the first placeholder. }
  1407.  
  1408. function FormatFloat(const Format: string; Value: Extended): string;
  1409.  
  1410. { FloatToTextFmt - Converts a floating point value to a string using a
  1411.   specified format. The result is written to Buffer without a
  1412.   terminating zero. The caller has to ensure that the buffer is large
  1413.   enough to hold the result. The number of characters actually written
  1414.   to Buffer is returned. See FormatFloat for a description of the
  1415.   Format parameter. }
  1416.  
  1417. function FloatToTextFmt(Buffer: PChar; Value: Extended;
  1418.   Format: PChar): Integer;
  1419.  
  1420. { StrToFloat - Converts a string to a floating point value. The string
  1421.   must contain a legal floating point value, with the decimal point
  1422.   being the same character as in the global variable DecimalSeparator.
  1423.   It must not contain thousand separators or currency symbols. Leading
  1424.   and trailing spaces are allowed. If the string does not conform
  1425.   these restrictions, EConvertError is raised. }
  1426.  
  1427. function StrToFloat(const S: string): Extended;
  1428.  
  1429. { TextToFloat - Converts a zero-terminated string to a floating point
  1430.   value. The string must contain a legal floating point value, with
  1431.   the decimal point being the same character as in the global variable
  1432.   DecimalSeparator. It must not contain thousand separators or
  1433.   currency symbols. Leading and trailing spaces are allowed. If the
  1434.   string does not conform these restrictions, EConvertError is raised. }
  1435.  
  1436. function TextToFloat(Buffer: PChar; var Value: Extended): Boolean;
  1437.  
  1438. { FloatToDecimal - Converts a floating point value to a TFLoatRec
  1439.   record which separates digits, sign, and exponent. The Precision
  1440.   parameter specifies the number of significant digits (with 1..18
  1441.   being legal values), the Decimals parameter specifies the desired
  1442.   minimum number of digits in the fractional part. Rounding is
  1443.   controlled by Precision as well as by Decimals. To force a number
  1444.   of significant digits even with large values, specify 9999 for
  1445.   Decimals.
  1446.  
  1447.   The resulting TFloatRec will contain the following information:
  1448.  
  1449.     Exponent - The result's exponent. An exponent value of -32768
  1450.     indicates that the value is not-a-number (NAN). Positive or
  1451.     negative infinity (INF / -INF) is indicated by an exponent
  1452.     value of 32767.
  1453.  
  1454.     Negative - Indicates whether the value is negative or not. Use
  1455.     this to distinguish positive from negative infinity, too. Zero
  1456.     is assumed to be non-negative.
  1457.  
  1458.     Digits - Contains the significant digits with a terminating
  1459.     zero (Chr(0)). Does not contain the decimal separator. Empty,
  1460.     if the value is not-a-number, or positive, or negative infinity. }
  1461.  
  1462. procedure FloatToDecimal(var Result: TFloatRec; Value: Extended;
  1463.   Precision, Decimals: Integer);
  1464.  
  1465. { --- Date / time handling --- }
  1466.  
  1467. { EncodeDate - Encodes the given year, month, and day into a single
  1468.   TDateTime value. The result contains the number of days passed since
  1469.   the 31-Dec-0000 and the given date, assuming Gregorian calendar has
  1470.   always been used. If any parameter contains an illegal value,
  1471.   EConvertError is raised. }
  1472.  
  1473. function EncodeDate(Year, Month, Day: Word): TDateTime;
  1474.  
  1475. { EncodeTime - Encodes the given hour, minute, second and millisecond
  1476.   into a single TDateTime value. The result contains the fractional
  1477.   part of the day passed since 00:00:00. It is always a value equal to
  1478.   or greater than zero and and smaller that one. If any parameter
  1479.   contains an illegal value, EConvertError is raised. }
  1480.  
  1481. function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
  1482.  
  1483. { DecodeDate - Extracts year, month, and day from a given TDateTime
  1484.   value. }
  1485.  
  1486. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
  1487.  
  1488. { DecodeTime - Extracts hour, minute, second, and millisecond from a
  1489.   given TDateTime value. }
  1490.  
  1491. procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
  1492.  
  1493. { DayOfWeek - Extracts the day of the week from a given TDateTime
  1494.   value. The days are numbered from 1 to 7 in the following order:
  1495.  
  1496.     Sun / Mon / Tue / Wed / Thu / Fri / Sat }
  1497.  
  1498. function DayOfWeek(Date: TDateTime): Integer;
  1499.  
  1500. { Date - Queries the current system date. }
  1501.  
  1502. function Date: TDateTime;
  1503.  
  1504. { Time - Queries the current system time. }
  1505.  
  1506. function Time: TDateTime;
  1507.  
  1508. { Now - Queries the current system date and time. }
  1509.  
  1510. function Now: TDateTime;
  1511.  
  1512. { DateToStr - Converts the date part of the given TDateTime value
  1513.   to a string, using the format specified in the global variable
  1514.   ShortDateFormat. }
  1515.  
  1516. function DateToStr(Date: TDateTime): string;
  1517.  
  1518. { TimeToStr - Converts the time part ao the given TDateTime value
  1519.   to a string, using the format specified in the global variable
  1520.   LongTimeFormat. }
  1521.  
  1522. function TimeToStr(Time: TDateTime): string;
  1523.  
  1524. { DateTimeToStr - Converts the given TDateTime value to a string
  1525.   using the formats specified in the global variables ShortDateFormat
  1526.   and LongTimeFormat. The time is only appended, if the TDateTime
  1527.   value contains a (fractional) time part different from 00:00:00. }
  1528.  
  1529. function DateTimeToStr(DateTime: TDateTime): string;
  1530.  
  1531. { StrToDate - Tries to exctract date information from a string.
  1532.   The functions expects the string to contain two or three numbers
  1533.   separated by the character given in the global variable
  1534.   DateSeparator. The order in which day, month, and year are
  1535.   expected is determined by the global variable DateOrder.
  1536.   If only two numbers are found, they are assumed to specify
  1537.   a month and day of the current year. If the year is smaller
  1538.   than 100, it is assumed to be a year of the current century.
  1539.   If no legal date can be extracted from the string,
  1540.   EConvertError is raised. }
  1541.  
  1542. function StrToDate(const S: string): TDateTime;
  1543.  
  1544. { StrToTime - Tries to exctract time information from a string.
  1545.   The functions expects the string to contain two or three numbers
  1546.   separated by the character given in the global variable
  1547.   TimeSeparator, optionally followed by 'AM' or 'PM' to indicate
  1548.   12-hour format. The first two numbers are taken as hour and
  1549.   minute, the optional third one as second. If no indicator for
  1550.   12-hour format is found, the time is assumed to be in 24-hour
  1551.   format. If no legal time can be extracted from the string,
  1552.   EConvertError is raised. }
  1553.  
  1554. function StrToTime(const S: string): TDateTime;
  1555.  
  1556. { StrToDateTime - Tries to extract date and time information from a
  1557.   string. The function expects the string to contain a date optionally
  1558.   followed by a time. See StrToDate and StrToTime for more details
  1559.   about the string's contents. If no legal date and time can be
  1560.   extracted from the string, EConvertError is raised. }
  1561.  
  1562. function StrToDateTime(const S: string): TDateTime;
  1563.  
  1564. { FormatDateTime - Converts a TDateTime value to a string using a
  1565.   format specified by the parameter Format.
  1566.  
  1567.   The format string may contain arbitrary text, which is simply
  1568.   copies to the result string. Some characters or character
  1569.   sequences have a special meaning, they serve as placeholders and
  1570.   are replaced by values extracted from DateTime.
  1571.  
  1572.   The following placeholders are allowed in the format string. Their
  1573.   case doesn't matter. If the format string is empty, 'c' is assumed
  1574.   the default format.
  1575.  
  1576.     c         Replaced by the date formatted as specified in the
  1577.               global variable ShortDateFormat. If the (fractional)
  1578.               time part is different from 00:00:00, the time is
  1579.               appended using the format specified in the global
  1580.               variable LongTimeFormat.
  1581.  
  1582.     d         Replaced by a number indicating the day of the month,
  1583.               with no leading zero.
  1584.  
  1585.     dd        Replaced by a number indicating the day of the month,
  1586.               with leading zero.
  1587.  
  1588.     ddd       Replaced by the day of the week's name taken from the
  1589.               global array ShortDayNames, resulting in an abbreviation
  1590.               of the day's name.
  1591.  
  1592.     dddd      Replaced by the day of the week's name taken from the
  1593.               global array LongDayNames, resulting in the day's full
  1594.               name.
  1595.  
  1596.     ddddd     Replaced by the date formatted as specified in the
  1597.               global variable ShortDateFormat.
  1598.  
  1599.     dddddd    Replaced by the date formatted as specified in the
  1600.               global variable LongDateFormat.
  1601.  
  1602.     m         When used immediately after an hour placeholder,
  1603.               replaced by the minute. Otherwise replaced by a
  1604.               number indicating the month. No leading zeroes.
  1605.  
  1606.     mm        When used immediately after an hour placeholder,
  1607.               replaced by the minute. Otherwise replaced by a
  1608.               number indicating the month. Leading zeroes.
  1609.  
  1610.     mmm       Replaced by the month's name taken from the global array
  1611.               ShortMonthNames, resulting in an abbreviation of the
  1612.               month's name.
  1613.  
  1614.     mmmm      Replaced by the month's name taken from the global array
  1615.               LongMonthNames, resulting in the month's full name.
  1616.  
  1617.     yy        Replaced by two digits indicating the year. Leading
  1618.               zeroes.
  1619.  
  1620.     yyyy      Replaced by four digits indicating the year. Leading
  1621.               zeroes.
  1622.  
  1623.     h         Replaced by the hour without leading zero.
  1624.  
  1625.     hh        Replaced by the hour with leading zero.
  1626.  
  1627.     n         Replaced by the minute without leading zero.
  1628.  
  1629.     nn        Replaced by the minute with leading zero.
  1630.  
  1631.     s         Replaced by the second without leading zero.
  1632.  
  1633.     ss        Replaced by the second with leading zero.
  1634.  
  1635.     t         Replaced by the time formatted as specified in the
  1636.               global variable ShortTimeFormat.
  1637.  
  1638.     tt        Replaced by the time formatted as specified in the
  1639.               global variable LongTimeFormat.
  1640.  
  1641.     am/pm     Indicates that 12-hour format should be used for the
  1642.               preceding hour placeholder. Replaced by 'am' or 'pm',
  1643.               depending on the time, with the same case as specified.
  1644.  
  1645.     a/p       Indicates that 12-hour format should be used for the
  1646.               preceding hour placeholder. Replaced by 'a' or 'p',
  1647.               depending on the time, with the same case as specified.
  1648.  
  1649.     ampm      Indicates that 12-hour format should be used for the
  1650.               preceding hour placeholder. Replaced by a string taken
  1651.               from the global variables TimeAMString or TimePMString,
  1652.               depending on the time.
  1653.  
  1654.     /         Replaced by the date separator as specified in the global
  1655.               variable DateSeparator.
  1656.  
  1657.     :         Replaced by the time separator as specified in the global
  1658.               variable TimeSeparator.
  1659.  
  1660.     '...'     Characters enclosed in single or double quotes will
  1661.     "..."     simply be copied to the result (without quotes). }
  1662.  
  1663. function FormatDateTime(const Format: string; DateTime: TDateTime): string;
  1664.  
  1665. { DateTimeToString - Converts a TDateTime value to a string using a
  1666.   format specified by the Format parameter . See FormatDateTime for
  1667.   a detailed description of the format string. }
  1668.  
  1669. procedure DateTimeToString(var Result: string; const Format: string;
  1670.   DateTime: TDateTime);
  1671.  
  1672. { --- System profile support --- }
  1673.  
  1674. {$ifdef GUI}
  1675.  
  1676. { GetProfileStr - Reads a string from the operating system's user
  1677.   profile. If Section or Entry don't exist, a Default value is
  1678.   returned instead. }
  1679.  
  1680. function GetProfileStr(const Section, Entry: cstring; const Default: string): string;
  1681.  
  1682. { GetProfileChar - Reads a character from the operating system's user
  1683.   profile. If Section or Entry don't exist, a Default value is
  1684.   returned instead. }
  1685.  
  1686. function GetProfileChar(const Section, Entry: cstring; Default: Char): Char;
  1687.  
  1688. { GetProfileInt - Reads an integer from the operating system's user
  1689.   profile. If Section or Entry don't exist, a Default value is
  1690.   returned instead. }
  1691.  
  1692. function GetProfileInt(const Section, Entry: cstring; Default: Integer): Integer;
  1693.  
  1694. { GetFormatSettings - Queries a lot of default values used for
  1695.   formatting functions from the operation system. Called automatically
  1696.   in the SysUtils startup code, so an application that uses SysUtils
  1697.   can always access these values immediately after program startup. }
  1698.  
  1699. {$endif GUI}
  1700.  
  1701. procedure GetFormatSettings;
  1702.  
  1703. { ConvertError - Raises EConvertError with the given error message. }
  1704.  
  1705. procedure ConvertError(const Msg: String);
  1706.  
  1707. { --- Some routines that belong into SYSTEM.PAS --- }
  1708.  
  1709. { SetLength - Changes the length of a string. Please use this
  1710.   procedure instead of writing S[0] := NewLength to maintain
  1711.   compatibility with the forthcoming long strings that won't contain
  1712.   a length-byte any more. }
  1713.  
  1714. { procedure SetLength(var S: string; NewLength: Byte); }
  1715.  
  1716. { StringOfChars - Returns a string that consists of
  1717.   Count occurences of the given character Ch. }
  1718.  
  1719. function StringOfChars(Ch: Char; Count: Integer): string;
  1720.  
  1721. { SetCurrentLanguageTable - sets the language table name to the specified language.
  1722.   The name must start with "SIBYL_NLS_". A table with the name must exist. If the table
  1723.   cannot be found or some other error occurs this function returns false, otherise true.
  1724.   By convention the table must include all Sibyl default language identifiers
  1725.   (see /LANGUAGE directory for examples).}
  1726.  
  1727. function SetCurrentLanguageTable(const Table:string):Boolean;
  1728.  
  1729. { GetCurrentLanguageTable - gets the current language table name. }
  1730.  
  1731. function GetCurrentLanguageTable:string;
  1732.  
  1733. { GetCurrentLanguage - returns the currently set language. The language string is
  1734.   retrieved from the current language table with the "SLanguage" index. This function
  1735.   returns an empty string on error. }
  1736.  
  1737. function GetCurrentLanguage:string;
  1738.  
  1739. implementation
  1740.  
  1741.