home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 August / VPR9608A.BIN / del20try / install / data.z / SYSUTILS.INT < prev    next >
Text File  |  1996-05-08  |  65KB  |  1,557 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Runtime Library                          }
  5. {       System Utilities Unit                           }
  6. {                                                       }
  7. {       Copyright (C) 1995,96 Borland International     }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit SysUtils;
  12.  
  13. {$H+}
  14.  
  15. interface
  16.  
  17. uses Windows;
  18.  
  19. const
  20.  
  21. { File open modes }
  22.  
  23.   fmOpenRead       = $0000;
  24.   fmOpenWrite      = $0001;
  25.   fmOpenReadWrite  = $0002;
  26.   fmShareCompat    = $0000;
  27.   fmShareExclusive = $0010;
  28.   fmShareDenyWrite = $0020;
  29.   fmShareDenyRead  = $0030;
  30.   fmShareDenyNone  = $0040;
  31.  
  32. { File attribute constants }
  33.  
  34.   faReadOnly  = $00000001;
  35.   faHidden    = $00000002;
  36.   faSysFile   = $00000004;
  37.   faVolumeID  = $00000008;
  38.   faDirectory = $00000010;
  39.   faArchive   = $00000020;
  40.   faAnyFile   = $0000003F;
  41.  
  42. { File mode magic numbers }
  43.  
  44.   fmClosed = $D7B0;
  45.   fmInput  = $D7B1;
  46.   fmOutput = $D7B2;
  47.   fmInOut  = $D7B3;
  48.  
  49. { Seconds and milliseconds per day }
  50.  
  51.   SecsPerDay = 24 * 60 * 60;
  52.   MSecsPerDay = SecsPerDay * 1000;
  53.  
  54. { Days between 1/1/0001 and 12/31/1899 }
  55.  
  56.   DateDelta = 693594;
  57.  
  58. type
  59.  
  60. { Type conversion records }
  61.  
  62.   WordRec = packed record
  63.     Lo, Hi: Byte;
  64.   end;
  65.  
  66.   LongRec = packed record
  67.     Lo, Hi: Word;
  68.   end;
  69.  
  70.   TMethod = record
  71.     Code, Data: Pointer;
  72.   end;
  73.  
  74. { General arrays }
  75.  
  76.   PByteArray = ^TByteArray;
  77.   TByteArray = array[0..32767] of Byte;
  78.  
  79.   PWordArray = ^TWordArray;
  80.   TWordArray = array[0..16383] of Word;
  81.  
  82. { Generic procedure pointer }
  83.  
  84.   TProcedure = procedure;
  85.  
  86. { Generic filename type }
  87.  
  88.   TFileName = string;
  89.  
  90. { Search record used by FindFirst, FindNext, and FindClose }
  91.  
  92.   TSearchRec = record
  93.     Time: Integer;
  94.     Size: Integer;
  95.     Attr: Integer;
  96.     Name: TFileName;
  97.     ExcludeAttr: Integer;
  98.     FindHandle: THandle;
  99.     FindData: TWin32FindData;
  100.   end;
  101.  
  102. { Typed-file and untyped-file record }
  103.  
  104.   TFileRec = record
  105.     Handle: Integer;
  106.     Mode: Integer;
  107.     RecSize: Cardinal;
  108.     Private: array[1..28] of Byte;
  109.     UserData: array[1..32] of Byte;
  110.     Name: array[0..259] of Char;
  111.   end;
  112.  
  113. { Text file record structure used for Text files }
  114.  
  115.   PTextBuf = ^TTextBuf;
  116.   TTextBuf = array[0..127] of Char;
  117.   TTextRec = record
  118.     Handle: Integer;
  119.     Mode: Integer;
  120.     BufSize: Cardinal;
  121.     BufPos: Cardinal;
  122.     BufEnd: Cardinal;
  123.     BufPtr: PChar;
  124.     OpenFunc: Pointer;
  125.     InOutFunc: Pointer;
  126.     FlushFunc: Pointer;
  127.     CloseFunc: Pointer;
  128.     UserData: array[1..32] of Byte;
  129.     Name: array[0..259] of Char;
  130.     Buffer: TTextBuf;
  131.   end;
  132.  
  133. { FloatToText, FloatToTextFmt, TextToFloat, and FloatToDecimal type codes }
  134.  
  135.   TFloatValue = (fvExtended, fvCurrency);
  136.  
  137. { FloatToText format codes }
  138.  
  139.   TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  140.  
  141. { FloatToDecimal result record }
  142.  
  143.   TFloatRec = packed record
  144.     Exponent: Smallint;
  145.     Negative: Boolean;
  146.     Digits: array[0..20] of Char;
  147.   end;
  148.  
  149. { Date and time record }
  150.  
  151.   TTimeStamp = record
  152.     Time: Integer;      { Number of milliseconds since midnight }
  153.     Date: Integer;      { One plus number of days since 1/1/0001 }
  154.   end;
  155.  
  156. { Exceptions }
  157.  
  158.   Exception = class(TObject)
  159.   public
  160.     constructor Create(const Msg: string);
  161.     constructor CreateFmt(const Msg: string; const Args: array of const);
  162.     constructor CreateRes(Ident: Integer);
  163.     constructor CreateResFmt(Ident: Integer; const Args: array of const);
  164.     constructor CreateHelp(const Msg: string; AHelpContext: Integer);
  165.     constructor CreateFmtHelp(const Msg: string; const Args: array of const;
  166.       AHelpContext: Integer);
  167.     constructor CreateResHelp(Ident: Integer; AHelpContext: Integer);
  168.     constructor CreateResFmtHelp(Ident: Integer; const Args: array of const;
  169.       AHelpContext: Integer);
  170.     property HelpContext: Integer;
  171.     property Message: string;
  172.   end;
  173.  
  174.   ExceptClass = class of Exception;
  175.  
  176.   EAbort = class(Exception);
  177.  
  178.   EOutOfMemory = class(Exception)
  179.   public
  180.     destructor Destroy; override;
  181.     procedure FreeInstance; override;
  182.   end;
  183.  
  184.   EInOutError = class(Exception)
  185.   public
  186.     ErrorCode: Integer;
  187.   end;
  188.  
  189.   EIntError = class(Exception);
  190.   EDivByZero = class(EIntError);
  191.   ERangeError = class(EIntError);
  192.   EIntOverflow = class(EIntError);
  193.  
  194.   EMathError = class(Exception);
  195.   EInvalidOp = class(EMathError);
  196.   EZeroDivide = class(EMathError);
  197.   EOverflow = class(EMathError);
  198.   EUnderflow = class(EMathError);
  199.  
  200.   EInvalidPointer = class(Exception);
  201.  
  202.   EInvalidCast = class(Exception);
  203.  
  204.   EConvertError = class(Exception);
  205.  
  206.   EAccessViolation = class(Exception);
  207.   EPrivilege = class(Exception);
  208.   EStackOverflow = class(Exception);
  209.   EControlC = class(Exception);
  210.  
  211.   EVariantError = class(Exception);
  212.  
  213.   EPropReadOnly = class(Exception);
  214.   EPropWriteOnly = class(Exception);
  215.  
  216.   EExternalException = class(Exception)
  217.   public
  218.     ExceptionRecord: PExceptionRecord;
  219.   end;
  220.  
  221. const
  222.  
  223. { Empty string and null string pointer. These constants are provided for
  224.   backwards compatibility only. }
  225.  
  226.   EmptyStr: string = '';
  227.   NullStr: PString = @EmptyStr;
  228.  
  229. { Win32 platform identifier.  This will be one of the following values:
  230.  
  231.     VER_PLATFORM_WIN32s
  232.     VER_PLATFORM_WIN32_WINDOWS
  233.     VER_PLATFORM_WIN32_NT
  234.  
  235.   See WINDOWS.PAS for the numerical values. }
  236.  
  237.   Win32Platform: Integer = 0;
  238.  
  239. { Currency and date/time formatting options
  240.  
  241.   The initial values of these variables are fetched from the system registry
  242.   using the GetLocaleInfo function in the Win32 API. The description of each
  243.   variable specifies the LOCALE_XXXX constant used to fetch the initial
  244.   value.
  245.  
  246.   CurrencyString - Defines the currency symbol used in floating-point to
  247.   decimal conversions. The initial value is fetched from LOCALE_SCURRENCY.
  248.  
  249.   CurrencyFormat - Defines the currency symbol placement and separation
  250.   used in floating-point to decimal conversions. Possible values are:
  251.  
  252.     0 = '$1'
  253.     1 = '1$'
  254.     2 = '$ 1'
  255.     3 = '1 $'
  256.  
  257.   The initial value is fetched from LOCALE_ICURRENCY.
  258.  
  259.   NegCurrFormat - Defines the currency format for used in floating-point to
  260.   decimal conversions of negative numbers. Possible values are:
  261.  
  262.     0 = '($1)'      4 = '(1$)'      8 = '-1 $'      12 = '$ -1'
  263.     1 = '-$1'       5 = '-1$'       9 = '-$ 1'      13 = '1- $'
  264.     2 = '$-1'       6 = '1-$'      10 = '1 $-'      14 = '($ 1)'
  265.     3 = '$1-'       7 = '1$-'      11 = '$ 1-'      15 = '(1 $)'
  266.  
  267.   The initial value is fetched from LOCALE_INEGCURR.
  268.  
  269.   ThousandSeparator - The character used to separate thousands in numbers
  270.   with more than three digits to the left of the decimal separator. The
  271.   initial value is fetched from LOCALE_STHOUSAND.
  272.  
  273.   DecimalSeparator - The character used to separate the integer part from
  274.   the fractional part of a number. The initial value is fetched from
  275.   LOCALE_SDECIMAL.
  276.  
  277.   CurrencyDecimals - The number of digits to the right of the decimal point
  278.   in a currency amount. The initial value is fetched from LOCALE_ICURRDIGITS.
  279.  
  280.   DateSeparator - The character used to separate the year, month, and day
  281.   parts of a date value. The initial value is fetched from LOCATE_SDATE.
  282.  
  283.   ShortDateFormat - The format string used to convert a date value to a
  284.   short string suitable for editing. For a complete description of date and
  285.   time format strings, refer to the documentation for the FormatDate
  286.   function. The short date format should only use the date separator
  287.   character and the  m, mm, d, dd, yy, and yyyy format specifiers. The
  288.   initial value is fetched from LOCALE_SSHORTDATE.
  289.  
  290.   LongDateFormat - The format string used to convert a date value to a long
  291.   string suitable for display but not for editing. For a complete description
  292.   of date and time format strings, refer to the documentation for the
  293.   FormatDate function. The initial value is fetched from LOCALE_SLONGDATE.
  294.  
  295.   TimeSeparator - The character used to separate the hour, minute, and
  296.   second parts of a time value. The initial value is fetched from
  297.   LOCALE_STIME.
  298.  
  299.   TimeAMString - The suffix string used for time values between 00:00 and
  300.   11:59 in 12-hour clock format. The initial value is fetched from
  301.   LOCALE_S1159.
  302.  
  303.   TimePMString - The suffix string used for time values between 12:00 and
  304.   23:59 in 12-hour clock format. The initial value is fetched from
  305.   LOCALE_S2359.
  306.  
  307.   ShortTimeFormat - The format string used to convert a time value to a
  308.   short string with only hours and minutes. The default value is computed
  309.   from LOCALE_ITIME and LOCALE_ITLZERO.
  310.  
  311.   LongTimeFormat - The format string used to convert a time value to a long
  312.   string with hours, minutes, and seconds. The default value is computed
  313.   from LOCALE_ITIME and LOCALE_ITLZERO.
  314.  
  315.   ShortMonthNames - Array of strings containing short month names. The mmm
  316.   format specifier in a format string passed to FormatDate causes a short
  317.   month name to be substituted. The default values are fecthed from the
  318.   LOCALE_SABBREVMONTHNAME system locale entries.
  319.  
  320.   LongMonthNames - Array of strings containing long month names. The mmmm
  321.   format specifier in a format string passed to FormatDate causes a long
  322.   month name to be substituted. The default values are fecthed from the
  323.   LOCALE_SMONTHNAME system locale entries.
  324.  
  325.   ShortDayNames - Array of strings containing short day names. The ddd
  326.   format specifier in a format string passed to FormatDate causes a short
  327.   day name to be substituted. The default values are fecthed from the
  328.   LOCALE_SABBREVDAYNAME system locale entries.
  329.  
  330.   LongDayNames - Array of strings containing long day names. The dddd
  331.   format specifier in a format string passed to FormatDate causes a long
  332.   day name to be substituted. The default values are fecthed from the
  333.   LOCALE_SDAYNAME system locale entries. }
  334.  
  335. var
  336.   CurrencyString: string;
  337.   CurrencyFormat: Byte;
  338.   NegCurrFormat: Byte;
  339.   ThousandSeparator: Char;
  340.   DecimalSeparator: Char;
  341.   CurrencyDecimals: Byte;
  342.   DateSeparator: Char;
  343.   ShortDateFormat: string;
  344.   LongDateFormat: string;
  345.   TimeSeparator: Char;
  346.   TimeAMString: string;
  347.   TimePMString: string;
  348.   ShortTimeFormat: string;
  349.   LongTimeFormat: string;
  350.   ShortMonthNames: array[1..12] of string;
  351.   LongMonthNames: array[1..12] of string;
  352.   ShortDayNames: array[1..7] of string;
  353.   LongDayNames: array[1..7] of string;
  354.  
  355. { Memory management routines }
  356.  
  357. { AllocMem allocates a block of the given size on the heap. Each byte in
  358.   the allocated buffer is set to zero. To dispose the buffer, use the
  359.   FreeMem standard procedure. }
  360.  
  361. function AllocMem(Size: Cardinal): Pointer;
  362.  
  363. { Exit procedure handling }
  364.  
  365. { AddExitProc adds the given procedure to the run-time library's exit
  366.   procedure list. When an application terminates, its exit procedures are
  367.   executed in reverse order of definition, i.e. the last procedure passed
  368.   to AddExitProc is the first one to get executed upon termination. }
  369.  
  370. procedure AddExitProc(Proc: TProcedure);
  371.  
  372. { String handling routines }
  373.  
  374. { NewStr allocates a string on the heap. NewStr is provided for backwards
  375.   compatibility only. }
  376.  
  377. function NewStr(const S: string): PString;
  378.  
  379. { DisposeStr disposes a string pointer that was previously allocated using
  380.   NewStr. DisposeStr is provided for backwards compatibility only. }
  381.  
  382. procedure DisposeStr(P: PString);
  383.  
  384. { AssignStr assigns a new dynamically allocated string to the given string
  385.   pointer. AssignStr is provided for backwards compatibility only. }
  386.  
  387. procedure AssignStr(var P: PString; const S: string);
  388.  
  389. { AppendStr appends S to the end of Dest. AppendStr is provided for
  390.   backwards compatibility only. Use "Dest := Dest + S" instead. }
  391.  
  392. procedure AppendStr(var Dest: string; const S: string);
  393.  
  394. { UpperCase converts all ASCII characters in the given string to upper case.
  395.   The conversion affects only 7-bit ASCII characters between 'a' and 'z'. To
  396.   convert 8-bit international characters, use AnsiUpperCase. }
  397.  
  398. function UpperCase(const S: string): string;
  399.  
  400. { UpperCase converts all ASCII characters in the given string to lower case.
  401.   The conversion affects only 7-bit ASCII characters between 'A' and 'Z'. To
  402.   convert 8-bit international characters, use AnsiLowerCase. }
  403.  
  404. function LowerCase(const S: string): string;
  405.  
  406. { CompareStr compares S1 to S2, with case-sensitivity. The return value is
  407.   less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2. The
  408.   compare operation is based on the 8-bit ordinal value of each character
  409.   and is not affected by the current Windows locale. }
  410.  
  411. function CompareStr(const S1, S2: string): Integer;
  412.  
  413. { CompareText compares S1 to S2, without case-sensitivity. The return value
  414.   is the same as for CompareStr. The compare operation is based on the 8-bit
  415.   ordinal value of each character, after converting 'a'..'z' to 'A'..'Z',
  416.   and is not affected by the current Windows locale. }
  417.  
  418. function CompareText(const S1, S2: string): Integer;
  419.  
  420. { AnsiUpperCase converts all characters in the given string to upper case.
  421.   The conversion uses the current Windows locale. }
  422.  
  423. function AnsiUpperCase(const S: string): string;
  424.  
  425. { AnsiLowerCase converts all characters in the given string to lower case.
  426.   The conversion uses the current Windows locale. }
  427.  
  428. function AnsiLowerCase(const S: string): string;
  429.  
  430. { AnsiCompareStr compares S1 to S2, with case-sensitivity. The compare
  431.   operation is controlled by the current Windows locale. The return value
  432.   is the same as for CompareStr. }
  433.  
  434. function AnsiCompareStr(const S1, S2: string): Integer;
  435.  
  436. { AnsiCompareText compares S1 to S2, without case-sensitivity. The compare
  437.   operation is controlled by the current Windows locale. The return value
  438.   is the same as for CompareStr. }
  439.  
  440. function AnsiCompareText(const S1, S2: string): Integer;
  441.  
  442. { Trim trims leading and trailing spaces and control characters from the
  443.   given string. }
  444.  
  445. function Trim(const S: string): string;
  446.  
  447. { TrimLeft trims leading spaces and control characters from the given
  448.   string. }
  449.  
  450. function TrimLeft(const S: string): string;
  451.  
  452. { TrimRight trims trailing spaces and control characters from the given
  453.   string. }
  454.  
  455. function TrimRight(const S: string): string;
  456.  
  457. { QuotedStr returns the given string as a quoted string. A single quote
  458.   character is inserted at the beginning and the end of the string, and
  459.   for each single quote character in the string, another one is added. }
  460.  
  461. function QuotedStr(const S: string): string;
  462.  
  463. { AdjustLineBreaks adjusts all line breaks in the given string to be true
  464.   CR/LF sequences. The function changes any CR characters not followed by
  465.   a LF and any LF characters not preceded by a CR into CR/LF pairs. }
  466.  
  467. function AdjustLineBreaks(const S: string): string;
  468.  
  469. { IsValidIdent returns true if the given string is a valid identifier. An
  470.   identifier is defined as a character from the set ['A'..'Z', 'a'..'z', '_']
  471.   followed by zero or more characters from the set ['A'..'Z', 'a'..'z',
  472.   '0..'9', '_']. }
  473.  
  474. function IsValidIdent(const Ident: string): Boolean;
  475.  
  476. { IntToStr converts the given value to its decimal string representation. }
  477.  
  478. function IntToStr(Value: Integer): string;
  479.  
  480. { IntToHex converts the given value to a hexadecimal string representation
  481.   with the minimum number of digits specified. }
  482.  
  483. function IntToHex(Value: Integer; Digits: Integer): string;
  484.  
  485. { StrToInt converts the given string to an integer value. If the string
  486.   doesn't contain a valid value, an EConvertError exception is raised. }
  487.  
  488. function StrToInt(const S: string): Integer;
  489.  
  490. { StrToIntDef converts the given string to an integer value. If the string
  491.   doesn't contain a valid value, the value given by Default is returned. }
  492.  
  493. function StrToIntDef(const S: string; Default: Integer): Integer;
  494.  
  495. { LoadStr loads the string resource given by Ident from the application's
  496.   executable file. If the string resource does not exist, an empty string
  497.   is returned. }
  498.  
  499. function LoadStr(Ident: Integer): string;
  500.  
  501. { LoadStr loads the string resource given by Ident from the application's
  502.   executable file, and uses it as the format string in a call to the
  503.   Format function with the given arguments. }
  504.  
  505. function FmtLoadStr(Ident: Integer; const Args: array of const): string;
  506.  
  507. { File management routines }
  508.  
  509. { FileOpen opens the specified file using the specified access mode. The
  510.   access mode value is constructed by OR-ing one of the fmOpenXXXX constants
  511.   with one of the fmShareXXXX constants. If the return value is positive,
  512.   the function was successful and the value is the file handle of the opened
  513.   file. A return value of -1 indicates that an error occurred. }
  514.  
  515. function FileOpen(const FileName: string; Mode: Integer): Integer;
  516.  
  517. { FileCreate creates a new file by the specified name. If the return value
  518.   is positive, the function was successful and the value is the file handle
  519.   of the new file. A return value of -1 indicates that an error occurred. }
  520.  
  521. function FileCreate(const FileName: string): Integer;
  522.  
  523. { FileRead reads Count bytes from the file given by Handle into the buffer
  524.   specified by Buffer. The return value is the number of bytes actually
  525.   read; it is less than Count if the end of the file was reached. The return
  526.   value is -1 if an error occurred. }
  527.  
  528. function FileRead(Handle: Integer; var Buffer; Count: Integer): Integer;
  529.  
  530. { FileWrite writes Count bytes to the file given by Handle from the buffer
  531.   specified by Buffer. The return value is the number of bytes actually
  532.   written, or -1 if an error occurred. }
  533.  
  534. function FileWrite(Handle: Integer; const Buffer; Count: Integer): Integer;
  535.  
  536. { FileSeek changes the current position of the file given by Handle to be
  537.   Offset bytes relative to the point given by Origin. Origin = 0 means that
  538.   Offset is relative to the beginning of the file, Origin = 1 means that
  539.   Offset is relative to the current position, and Origin = 2 means that
  540.   Offset is relative to the end of the file. The return value is the new
  541.   current position, relative to the beginning of the file, or -1 if an error
  542.   occurred. }
  543.  
  544. function FileSeek(Handle, Offset, Origin: Integer): Integer;
  545.  
  546. { FileClose closes the specified file. }
  547.  
  548. procedure FileClose(Handle: Integer);
  549.  
  550. { FileAge returns the date-and-time stamp of the specified file. The return
  551.   value can be converted to a TDateTime value using the FileDateToDateTime
  552.   function. The return value is -1 if the file does not exist. }
  553.  
  554. function FileAge(const FileName: string): Integer;
  555.  
  556. { FileExists returns a boolean value that indicates whether the specified
  557.   file exists. }
  558.  
  559. function FileExists(const FileName: string): Boolean;
  560.  
  561. { FindFirst searches the directory given by Path for the first entry that
  562.   matches the filename given by Path and the attributes given by Attr. The
  563.   result is returned in the search record given by SearchRec. The return
  564.   value is zero if the function was successful. Otherwise the return value
  565.   is a Windows error code. FindFirst is typically used in conjunction with
  566.   FindNext and FindClose as follows:
  567.  
  568.     Result := FindFirst(Path, Attr, SearchRec);
  569.     while Result = 0 do
  570.     begin
  571.       ProcessSearchRec(SearchRec);
  572.       Result := FindNext(SearchRec);
  573.     end;
  574.     FindClose(SearchRec);
  575.  
  576.   where ProcessSearchRec represents user-defined code that processes the
  577.   information in a search record. }
  578.  
  579. function FindFirst(const Path: string; Attr: Integer;
  580.   var F: TSearchRec): Integer;
  581.  
  582. { FindNext returs the next entry that matches the name and attributes
  583.   specified in a previous call to FindFirst. The search record must be one
  584.   that was passed to FindFirst. The return value is zero if the function was
  585.   successful. Otherwise the return value is a Windows error code. }
  586.  
  587. function FindNext(var F: TSearchRec): Integer;
  588.  
  589. { FindClose terminates a FindFirst/FindNext sequence. FindClose does nothing
  590.   in the 16-bit version of Windows, but is required in the 32-bit version,
  591.   so for maximum portability every FindFirst/FindNext sequence should end
  592.   with a call to FindClose. }
  593.  
  594. procedure FindClose(var F: TSearchRec);
  595.  
  596. { FileGetDate returns the DOS date-and-time stamp of the file given by
  597.   Handle. The return value is -1 if the handle is invalid. The
  598.   FileDateToDateTime function can be used to convert the returned value to
  599.   a TDateTime value. }
  600.  
  601. function FileGetDate(Handle: Integer): Integer;
  602.  
  603. { FileSetDate sets the DOS date-and-time stamp of the file given by Handle
  604.   to the value given by Age. The DateTimeToFileDate function can be used to
  605.   convert a TDateTime value to a DOS date-and-time stamp. The return value
  606.   is zero if the function was successful. Otherwise the return value is a
  607.   Windows error code. }
  608.  
  609. function FileSetDate(Handle: Integer; Age: Integer): Integer;
  610.  
  611. { FileGetAttr returns the file attributes of the file given by FileName. The
  612.   attributes can be examined by AND-ing with the faXXXX constants defined
  613.   above. A return value of -1 indicates that an error occurred. }
  614.  
  615. function FileGetAttr(const FileName: string): Integer;
  616.  
  617. { FileSetAttr sets the file attributes of the file given by FileName to the
  618.   value given by Attr. The attribute value is formed by OR-ing the
  619.   appropriate faXXXX constants. The return value is zero if the function was
  620.   successful. Otherwise the return value is a Windows error code. }
  621.  
  622. function FileSetAttr(const FileName: string; Attr: Integer): Integer;
  623.  
  624. { DeleteFile deletes the file given by FileName. The return value is True if
  625.   the file was successfully deleted, or False if an error occurred. }
  626.  
  627. function DeleteFile(const FileName: string): Boolean;
  628.  
  629. { RenameFile renames the file given by OldName to the name given by NewName.
  630.   The return value is True if the file was successfully renamed, or False if
  631.   an error occurred. }
  632.  
  633. function RenameFile(const OldName, NewName: string): Boolean;
  634.  
  635. { ChangeFileExt changes the extension of a filename. FileName specifies a
  636.   filename with or without an extension, and Extension specifies the new
  637.   extension for the filename. The new extension can be a an empty string or
  638.   a period followed by up to three characters. }
  639.  
  640. function ChangeFileExt(const FileName, Extension: string): string;
  641.  
  642. { ExtractFilePath extracts the drive and directory parts of the given
  643.   filename. The resulting string is the rightmost characters of FileName,
  644.   up to and including the colon or backslash that separates the path
  645.   information from the name and extension. The resulting string is empty
  646.   if FileName contains no drive and directory parts. }
  647.  
  648. function ExtractFilePath(const FileName: string): string;
  649.  
  650. { ExtractFileDir extracts the drive and directory parts of the given
  651.   filename. The resulting string is a directory name suitable for passing
  652.   to SetCurrentDir, CreateDir, etc. The resulting string is empty if
  653.   FileName contains no drive and directory parts. }
  654.  
  655. function ExtractFileDir(const FileName: string): string;
  656.  
  657. { ExtractFileDrive extracts the drive part of the given filename.  For
  658.   filenames with drive letters, the resulting string is '<drive>:'.
  659.   For filenames with a UNC path, the resulting string is in the form
  660.   '\\<servername>\<sharename>'.  If the given path contains neither
  661.   style of filename, the result is an empty string. }
  662.  
  663. function ExtractFileDrive(const FileName: string): string;
  664.  
  665. { ExtractFileName extracts the name and extension parts of the given
  666.   filename. The resulting string is the leftmost characters of FileName,
  667.   starting with the first character after the colon or backslash that
  668.   separates the path information from the name and extension. The resulting
  669.   string is equal to FileName if FileName contains no drive and directory
  670.   parts. }
  671.  
  672. function ExtractFileName(const FileName: string): string;
  673.  
  674. { ExtractFileExt extracts the extension part of the given filename. The
  675.   resulting string includes the period character that separates the name
  676.   and extension parts. The resulting string is empty if the given filename
  677.   has no extension. }
  678.  
  679. function ExtractFileExt(const FileName: string): string;
  680.  
  681. { ExpandFileName expands the given filename to a fully qualified filename.
  682.   The resulting string consists of a drive letter, a colon, a root relative
  683.   directory path, and a filename. Embedded '.' and '..' directory references
  684.   are removed. }
  685.  
  686. function ExpandFileName(const FileName: string): string;
  687.  
  688. { ExpandUNCFileName expands the given filename to a fully qualified filename.
  689.   This function is the same as ExpandFileName except that it will return the
  690.   drive portion of the filename in the format '\\<servername>\<sharename> if
  691.   that drive is actually a network resource instead of a local resource.
  692.   Like ExpandFileName, embedded '.' and '..' directory references are
  693.   removed. }
  694.  
  695. function ExpandUNCFileName(const FileName: string): string;
  696.  
  697. { FileSearch searches for the file given by Name in the list of directories
  698.   given by DirList. The directory paths in DirList must be separated by
  699.   semicolons. The search always starts with the current directory of the
  700.   current drive. The returned value is a concatenation of one of the
  701.   directory paths and the filename, or an empty string if the file could not
  702.   be located. }
  703.  
  704. function FileSearch(const Name, DirList: string): string;
  705.  
  706. { DiskFree returns the number of free bytes on the specified drive number,
  707.   where 0 = Current, 1 = A, 2 = B, etc. DiskFree returns -1 if the drive
  708.   number is invalid. }
  709.  
  710. function DiskFree(Drive: Byte): Integer;
  711.  
  712. { DiskSize returns the size in bytes of the specified drive number, where
  713.   0 = Current, 1 = A, 2 = B, etc. DiskSize returns -1 if the drive number
  714.   is invalid. }
  715.  
  716. function DiskSize(Drive: Byte): Integer;
  717.  
  718. { FileDateToDateTime converts a DOS date-and-time value to a TDateTime
  719.   value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
  720.   date-and-time values, and the Time field of a TSearchRec used by the
  721.   FindFirst and FindNext functions contains a DOS date-and-time value. }
  722.  
  723. function FileDateToDateTime(FileDate: Integer): TDateTime;
  724.  
  725. { DateTimeToFileDate converts a TDateTime value to a DOS date-and-time
  726.   value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
  727.   date-and-time values, and the Time field of a TSearchRec used by the
  728.   FindFirst and FindNext functions contains a DOS date-and-time value. }
  729.  
  730. function DateTimeToFileDate(DateTime: TDateTime): Integer;
  731.  
  732. { GetCurrentDir returns the current directory. }
  733.  
  734. function GetCurrentDir: string;
  735.  
  736. { SetCurrentDir sets the current directory. The return value is True if
  737.   the current directory was successfully changed, or False if an error
  738.   occurred. }
  739.  
  740. function SetCurrentDir(const Dir: string): Boolean;
  741.  
  742. { CreateDir creates a new directory. The return value is True if a new
  743.   directory was successfully created, or False if an error occurred. }
  744.  
  745. function CreateDir(const Dir: string): Boolean;
  746.  
  747. { RemoveDir deletes an existing empty directory. The return value is
  748.   True if the directory was successfully deleted, or False if an error
  749.   occurred. }
  750.  
  751. function RemoveDir(const Dir: string): Boolean;
  752.  
  753. { PChar routines }
  754.  
  755. { StrLen returns the number of characters in Str, not counting the null
  756.   terminator. }
  757.  
  758. function StrLen(Str: PChar): Cardinal;
  759.  
  760. { StrEnd returns a pointer to the null character that terminates Str. }
  761.  
  762. function StrEnd(Str: PChar): PChar;
  763.  
  764. { StrMove copies exactly Count characters from Source to Dest and returns
  765.   Dest. Source and Dest may overlap. }
  766.  
  767. function StrMove(Dest, Source: PChar; Count: Cardinal): PChar;
  768.  
  769. { StrCopy copies Source to Dest and returns Dest. }
  770.  
  771. function StrCopy(Dest, Source: PChar): PChar;
  772.  
  773. { StrECopy copies Source to Dest and returns StrEnd(Dest). }
  774.  
  775. function StrECopy(Dest, Source: PChar): PChar;
  776.  
  777. { StrLCopy copies at most MaxLen characters from Source to Dest and
  778.   returns Dest. }
  779.  
  780. function StrLCopy(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  781.  
  782. { StrPCopy copies the Pascal style string Source into Dest and
  783.   returns Dest. }
  784.  
  785. function StrPCopy(Dest: PChar; const Source: string): PChar;
  786.  
  787. { StrPLCopy copies at most MaxLen characters from the Pascal style string
  788.   Source into Dest and returns Dest. }
  789.  
  790. function StrPLCopy(Dest: PChar; const Source: string;
  791.   MaxLen: Cardinal): PChar;
  792.  
  793. { StrCat appends a copy of Source to the end of Dest and returns Dest. }
  794.  
  795. function StrCat(Dest, Source: PChar): PChar;
  796.  
  797. { StrLCat appends at most MaxLen - StrLen(Dest) characters from Source to
  798.   the end of Dest, and returns Dest. }
  799.  
  800. function StrLCat(Dest, Source: PChar; MaxLen: Cardinal): PChar;
  801.  
  802. { StrComp compares Str1 to Str2. The return value is less than 0 if
  803.   Str1 < Str2, 0 if Str1 = Str2, or greater than 0 if Str1 > Str2. }
  804.  
  805. function StrComp(Str1, Str2: PChar): Integer;
  806.  
  807. { StrIComp compares Str1 to Str2, without case sensitivity. The return
  808.   value is the same as StrComp. }
  809.  
  810. function StrIComp(Str1, Str2: PChar): Integer;
  811.  
  812. { StrLComp compares Str1 to Str2, for a maximum length of MaxLen
  813.   characters. The return value is the same as StrComp. }
  814.  
  815. function StrLComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  816.  
  817. { StrLIComp compares Str1 to Str2, for a maximum length of MaxLen
  818.   characters, without case sensitivity. The return value is the same
  819.   as StrComp. }
  820.  
  821. function StrLIComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
  822.  
  823. { StrScan returns a pointer to the first occurrence of Chr in Str. If Chr
  824.   does not occur in Str, StrScan returns NIL. The null terminator is
  825.   considered to be part of the string. }
  826.  
  827. function StrScan(Str: PChar; Chr: Char): PChar;
  828.  
  829. { StrRScan returns a pointer to the last occurrence of Chr in Str. If Chr
  830.   does not occur in Str, StrRScan returns NIL. The null terminator is
  831.   considered to be part of the string. }
  832.  
  833. function StrRScan(Str: PChar; Chr: Char): PChar;
  834.  
  835. { StrPos returns a pointer to the first occurrence of Str2 in Str1. If
  836.   Str2 does not occur in Str1, StrPos returns NIL. }
  837.  
  838. function StrPos(Str1, Str2: PChar): PChar;
  839.  
  840. { StrUpper converts Str to upper case and returns Str. }
  841.  
  842. function StrUpper(Str: PChar): PChar;
  843.  
  844. { StrLower converts Str to lower case and returns Str. }
  845.  
  846. function StrLower(Str: PChar): PChar;
  847.  
  848. { StrPas converts Str to a Pascal style string. This function is provided
  849.   for backwards compatibility only. To convert a null terminated string to
  850.   a Pascal style string, use a type cast or an assignment. }
  851.  
  852. function StrPas(Str: PChar): string;
  853.  
  854. { StrAlloc allocates a buffer of the given size on the heap. The size of
  855.   the allocated buffer is encoded in a four byte header that immediately
  856.   preceeds the buffer. To dispose the buffer, use StrDispose. }
  857.  
  858. function StrAlloc(Size: Cardinal): PChar;
  859.  
  860. { StrBufSize returns the allocated size of the given buffer, not including
  861.   the two byte header. }
  862.  
  863. function StrBufSize(Str: PChar): Cardinal;
  864.  
  865. { StrNew allocates a copy of Str on the heap. If Str is NIL, StrNew returns
  866.   NIL and doesn't allocate any heap space. Otherwise, StrNew makes a
  867.   duplicate of Str, obtaining space with a call to the StrAlloc function,
  868.   and returns a pointer to the duplicated string. To dispose the string,
  869.   use StrDispose. }
  870.  
  871. function StrNew(Str: PChar): PChar;
  872.  
  873. { StrDispose disposes a string that was previously allocated with StrAlloc
  874.   or StrNew. If Str is NIL, StrDispose does nothing. }
  875.  
  876. procedure StrDispose(Str: PChar);
  877.  
  878. { String formatting routines }
  879.  
  880. { The Format routine formats the argument list given by the Args parameter
  881.   using the format string given by the Format parameter.
  882.  
  883.   Format strings contain two types of objects--plain characters and format
  884.   specifiers. Plain characters are copied verbatim to the resulting string.
  885.   Format specifiers fetch arguments from the argument list and apply
  886.   formatting to them.
  887.  
  888.   Format specifiers have the following form:
  889.  
  890.     "%" [index ":"] ["-"] [width] ["." prec] type
  891.  
  892.   A format specifier begins with a % character. After the % come the
  893.   following, in this order:
  894.  
  895.   -  an optional argument index specifier, [index ":"]
  896.   -  an optional left-justification indicator, ["-"]
  897.   -  an optional width specifier, [width]
  898.   -  an optional precision specifier, ["." prec]
  899.   -  the conversion type character, type
  900.  
  901.   The following conversion characters are supported:
  902.  
  903.   d  Decimal. The argument must be an integer value. The value is converted
  904.      to a string of decimal digits. If the format string contains a precision
  905.      specifier, it indicates that the resulting string must contain at least
  906.      the specified number of digits; if the value has less digits, the
  907.      resulting string is left-padded with zeros.
  908.  
  909.   e  Scientific. The argument must be a floating-point value. The value is
  910.      converted to a string of the form "-d.ddd...E+ddd". The resulting
  911.      string starts with a minus sign if the number is negative, and one digit
  912.      always precedes the decimal point. The total number of digits in the
  913.      resulting string (including the one before the decimal point) is given
  914.      by the precision specifer in the format string--a default precision of
  915.      15 is assumed if no precision specifer is present. The "E" exponent
  916.      character in the resulting string is always followed by a plus or minus
  917.      sign and at least three digits.
  918.  
  919.   f  Fixed. The argument must be a floating-point value. The value is
  920.      converted to a string of the form "-ddd.ddd...". The resulting string
  921.      starts with a minus sign if the number is negative. The number of digits
  922.      after the decimal point is given by the precision specifier in the
  923.      format string--a default of 2 decimal digits is assumed if no precision
  924.      specifier is present.
  925.  
  926.   g  General. The argument must be a floating-point value. The value is
  927.      converted to the shortest possible decimal string using fixed or
  928.      scientific format. The number of significant digits in the resulting
  929.      string is given by the precision specifier in the format string--a
  930.      default precision of 15 is assumed if no precision specifier is present.
  931.      Trailing zeros are removed from the resulting string, and a decimal
  932.      point appears only if necessary. The resulting string uses fixed point
  933.      format if the number of digits to the left of the decimal point in the
  934.      value is less than or equal to the specified precision, and if the
  935.      value is greater than or equal to 0.00001. Otherwise the resulting
  936.      string uses scientific format.
  937.  
  938.   n  Number. The argument must be a floating-point value. The value is
  939.      converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format
  940.      corresponds to the "f" format, except that the resulting string
  941.      contains thousand separators.
  942.  
  943.   m  Money. The argument must be a floating-point value. The value is
  944.      converted to a string that represents a currency amount. The conversion
  945.      is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat,
  946.      ThousandSeparator, DecimalSeparator, and CurrencyDecimals global
  947.      variables, all of which are initialized from the Currency Format in
  948.      the International section of the Windows Control Panel. If the format
  949.      string contains a precision specifier, it overrides the value given
  950.      by the CurrencyDecimals global variable.
  951.  
  952.   p  Pointer. The argument must be a pointer value. The value is converted
  953.      to a string of the form "XXXX:YYYY" where XXXX and YYYY are the
  954.      segment and offset parts of the pointer expressed as four hexadecimal
  955.      digits.
  956.  
  957.   s  String. The argument must be a character, a string, or a PChar value.
  958.      The string or character is inserted in place of the format specifier.
  959.      The precision specifier, if present in the format string, specifies the
  960.      maximum length of the resulting string. If the argument is a string
  961.      that is longer than this maximum, the string is truncated.
  962.  
  963.   x  Hexadecimal. The argument must be an integer value. The value is
  964.      converted to a string of hexadecimal digits. If the format string
  965.      contains a precision specifier, it indicates that the resulting string
  966.      must contain at least the specified number of digits; if the value has
  967.      less digits, the resulting string is left-padded with zeros.
  968.  
  969.   Conversion characters may be specified in upper case as well as in lower
  970.   case--both produce the same results.
  971.  
  972.   For all floating-point formats, the actual characters used as decimal and
  973.   thousand separators are obtained from the DecimalSeparator and
  974.   ThousandSeparator global variables.
  975.  
  976.   Index, width, and precision specifiers can be specified directly using
  977.   decimal digit string (for example "%10d"), or indirectly using an asterisk
  978.   charcater (for example "%*.*f"). When using an asterisk, the next argument
  979.   in the argument list (which must be an integer value) becomes the value
  980.   that is actually used. For example "Format('%*.*f', [8, 2, 123.456])" is
  981.   the same as "Format('%8.2f', [123.456])".
  982.  
  983.   A width specifier sets the minimum field width for a conversion. If the
  984.   resulting string is shorter than the minimum field width, it is padded
  985.   with blanks to increase the field width. The default is to right-justify
  986.   the result by adding blanks in front of the value, but if the format
  987.   specifier contains a left-justification indicator (a "-" character
  988.   preceding the width specifier), the result is left-justified by adding
  989.   blanks after the value.
  990.  
  991.   An index specifier sets the current argument list index to the specified
  992.   value. The index of the first argument in the argument list is 0. Using
  993.   index specifiers, it is possible to format the same argument multiple
  994.   times. For example "Format('%d %d %0:d %d', [10, 20])" produces the string
  995.   '10 20 10 20'.
  996.  
  997.   The Format function can be combined with other formatting functions. For
  998.   example
  999.  
  1000.     S := Format('Your total was %s on %s', [
  1001.       FormatFloat('$#,##0.00;;zero', Total),
  1002.       FormatDateTime('mm/dd/yy', Date)]);
  1003.  
  1004.   which uses the FormatFloat and FormatDateTime functions to customize the
  1005.   format beyond what is possible with Format. }
  1006.  
  1007. function Format(const Format: string; const Args: array of const): string;
  1008.  
  1009. { FmtStr formats the argument list given by Args using the format string
  1010.   given by Format into the string variable given by Result. For further
  1011.   details, see the description of the Format function. }
  1012.  
  1013. procedure FmtStr(var Result: string; const Format: string;
  1014.   const Args: array of const);
  1015.  
  1016. { StrFmt formats the argument list given by Args using the format string
  1017.   given by Format into the buffer given by Buffer. It is up to the caller to
  1018.   ensure that Buffer is large enough for the resulting string. The returned
  1019.   value is Buffer. For further details, see the description of the Format
  1020.   function. }
  1021.  
  1022. function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar;
  1023.  
  1024. { StrFmt formats the argument list given by Args using the format string
  1025.   given by Format into the buffer given by Buffer. The resulting string will
  1026.   contain no more than MaxLen characters, not including the null terminator.
  1027.   The returned value is Buffer. For further details, see the description of
  1028.   the Format function. }
  1029.  
  1030. function StrLFmt(Buffer: PChar; MaxLen: Cardinal; Format: PChar;
  1031.   const Args: array of const): PChar;
  1032.  
  1033. { FormatBuf formats the argument list given by Args using the format string
  1034.   given by Format and FmtLen into the buffer given by Buffer and BufLen.
  1035.   The Format parameter is a reference to a buffer containing FmtLen
  1036.   characters, and the Buffer parameter is a reference to a buffer of BufLen
  1037.   characters. The returned value is the number of characters actually stored
  1038.   in Buffer. The returned value is always less than or equal to BufLen. For
  1039.   further details, see the description of the Format function. }
  1040.  
  1041. function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
  1042.   FmtLen: Cardinal; const Args: array of const): Cardinal;
  1043.  
  1044. { Floating point conversion routines }
  1045.  
  1046. { FloatToStr converts the floating-point value given by Value to its string
  1047.   representation. The conversion uses general number format with 15
  1048.   significant digits. For further details, see the description of the
  1049.   FloatToStrF function. }
  1050.  
  1051. function FloatToStr(Value: Extended): string;
  1052.  
  1053. { CurrToStr converts the currency value given by Value to its string
  1054.   representation. The conversion uses general number format. For further
  1055.   details, see the description of the CurrToStrF function. }
  1056.  
  1057. function CurrToStr(Value: Currency): string;
  1058.  
  1059. { FloatToStrF converts the floating-point value given by Value to its string
  1060.   representation. The Format parameter controls the format of the resulting
  1061.   string. The Precision parameter specifies the precision of the given value.
  1062.   It should be 7 or less for values of type Single, 15 or less for values of
  1063.   type Double, and 18 or less for values of type Extended. The meaning of the
  1064.   Digits parameter depends on the particular format selected.
  1065.  
  1066.   The possible values of the Format parameter, and the meaning of each, are
  1067.   described below.
  1068.  
  1069.   ffGeneral - General number format. The value is converted to the shortest
  1070.   possible decimal string using fixed or scientific format. Trailing zeros
  1071.   are removed from the resulting string, and a decimal point appears only
  1072.   if necessary. The resulting string uses fixed point format if the number
  1073.   of digits to the left of the decimal point in the value is less than or
  1074.   equal to the specified precision, and if the value is greater than or
  1075.   equal to 0.00001. Otherwise the resulting string uses scientific format,
  1076.   and the Digits parameter specifies the minimum number of digits in the
  1077.   exponent (between 0 and 4).
  1078.  
  1079.   ffExponent - Scientific format. The value is converted to a string of the
  1080.   form "-d.ddd...E+dddd". The resulting string starts with a minus sign if
  1081.   the number is negative, and one digit always precedes the decimal point.
  1082.   The total number of digits in the resulting string (including the one
  1083.   before the decimal point) is given by the Precision parameter. The "E"
  1084.   exponent character in the resulting string is always followed by a plus
  1085.   or minus sign and up to four digits. The Digits parameter specifies the
  1086.   minimum number of digits in the exponent (between 0 and 4).
  1087.  
  1088.   ffFixed - Fixed point format. The value is converted to a string of the
  1089.   form "-ddd.ddd...". The resulting string starts with a minus sign if the
  1090.   number is negative, and at least one digit always precedes the decimal
  1091.   point. The number of digits after the decimal point is given by the Digits
  1092.   parameter--it must be between 0 and 18. If the number of digits to the
  1093.   left of the decimal point is greater than the specified precision, the
  1094.   resulting value will use scientific format.
  1095.  
  1096.   ffNumber - Number format. The value is converted to a string of the form
  1097.   "-d,ddd,ddd.ddd...". The ffNumber format corresponds to the ffFixed format,
  1098.   except that the resulting string contains thousand separators.
  1099.  
  1100.   ffCurrency - Currency format. The value is converted to a string that
  1101.   represents a currency amount. The conversion is controlled by the
  1102.   CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, and
  1103.   DecimalSeparator global variables, all of which are initialized from the
  1104.   Currency Format in the International section of the Windows Control Panel.
  1105.   The number of digits after the decimal point is given by the Digits
  1106.   parameter--it must be between 0 and 18.
  1107.  
  1108.   For all formats, the actual characters used as decimal and thousand
  1109.   separators are obtained from the DecimalSeparator and ThousandSeparator
  1110.   global variables.
  1111.  
  1112.   If the given value is a NAN (not-a-number), the resulting string is 'NAN'.
  1113.   If the given value is positive infinity, the resulting string is 'INF'. If
  1114.   the given value is negative infinity, the resulting string is '-INF'. }
  1115.  
  1116. function FloatToStrF(Value: Extended; Format: TFloatFormat;
  1117.   Precision, Digits: Integer): string;
  1118.  
  1119. { CurrToStrF converts the currency value given by Value to its string
  1120.   representation. A call to CurrToStrF corresponds to a call to
  1121.   FloatToStrF with an implied precision of 19 digits. }
  1122.  
  1123. function CurrToStrF(Value: Currency; Format: TFloatFormat;
  1124.   Digits: Integer): string;
  1125.  
  1126. { FloatToText converts the given floating-point value to its decimal
  1127.   representation using the specified format, precision, and digits. The
  1128.   Value parameter must be a variable of type Extended or Currency, as
  1129.   indicated by the ValueType parameter. The resulting string of characters
  1130.   is stored in the given buffer, and the returned value is the number of
  1131.   characters stored. The resulting string is not null-terminated. For
  1132.   further details, see the description of the FloatToStrF function. }
  1133.  
  1134. function FloatToText(Buffer: PChar; const Value; ValueType: TFloatValue;
  1135.   Format: TFloatFormat; Precision, Digits: Integer): Integer;
  1136.  
  1137. { FormatFloat formats the floating-point value given by Value using the
  1138.   format string given by Format. The following format specifiers are
  1139.   supported in the format string:
  1140.  
  1141.   0     Digit placeholder. If the value being formatted has a digit in the
  1142.         position where the '0' appears in the format string, then that digit
  1143.         is copied to the output string. Otherwise, a '0' is stored in that
  1144.         position in the output string.
  1145.  
  1146.   #     Digit placeholder. If the value being formatted has a digit in the
  1147.         position where the '#' appears in the format string, then that digit
  1148.         is copied to the output string. Otherwise, nothing is stored in that
  1149.         position in the output string.
  1150.  
  1151.   .     Decimal point. The first '.' character in the format string
  1152.         determines the location of the decimal separator in the formatted
  1153.         value; any additional '.' characters are ignored. The actual
  1154.         character used as a the decimal separator in the output string is
  1155.         determined by the DecimalSeparator global variable. The default value
  1156.         of DecimalSeparator is specified in the Number Format of the
  1157.         International section in the Windows Control Panel.
  1158.  
  1159.   ,     Thousand separator. If the format string contains one or more ','
  1160.         characters, the output will have thousand separators inserted between
  1161.         each group of three digits to the left of the decimal point. The
  1162.         placement and number of ',' characters in the format string does not
  1163.         affect the output, except to indicate that thousand separators are
  1164.         wanted. The actual character used as a the thousand separator in the
  1165.         output is determined by the ThousandSeparator global variable. The
  1166.         default value of ThousandSeparator is specified in the Number Format
  1167.         of the International section in the Windows Control Panel.
  1168.  
  1169.   E+    Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-'
  1170.   E-    are contained in the format string, the number is formatted using
  1171.   e+    scientific notation. A group of up to four '0' characters can
  1172.   e-    immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine the
  1173.         minimum number of digits in the exponent. The 'E+' and 'e+' formats
  1174.         cause a plus sign to be output for positive exponents and a minus
  1175.         sign to be output for negative exponents. The 'E-' and 'e-' formats
  1176.         output a sign character only for negative exponents.
  1177.  
  1178.   'xx'  Characters enclosed in single or double quotes are output as-is, and
  1179.   "xx"  do not affect formatting.
  1180.  
  1181.   ;     Separates sections for positive, negative, and zero numbers in the
  1182.         format string.
  1183.  
  1184.   The locations of the leftmost '0' before the decimal point in the format
  1185.   string and the rightmost '0' after the decimal point in the format string
  1186.   determine the range of digits that are always present in the output string.
  1187.  
  1188.   The number being formatted is always rounded to as many decimal places as
  1189.   there are digit placeholders ('0' or '#') to the right of the decimal
  1190.   point. If the format string contains no decimal point, the value being
  1191.   formatted is rounded to the nearest whole number.
  1192.  
  1193.   If the number being formatted has more digits to the left of the decimal
  1194.   separator than there are digit placeholders to the left of the '.'
  1195.   character in the format string, the extra digits are output before the
  1196.   first digit placeholder.
  1197.  
  1198.   To allow different formats for positive, negative, and zero values, the
  1199.   format string can contain between one and three sections separated by
  1200.   semicolons.
  1201.  
  1202.   One section - The format string applies to all values.
  1203.  
  1204.   Two sections - The first section applies to positive values and zeros, and
  1205.   the second section applies to negative values.
  1206.  
  1207.   Three sections - The first section applies to positive values, the second
  1208.   applies to negative values, and the third applies to zeros.
  1209.  
  1210.   If the section for negative values or the section for zero values is empty,
  1211.   that is if there is nothing between the semicolons that delimit the
  1212.   section, the section for positive values is used instead.
  1213.  
  1214.   If the section for positive values is empty, or if the entire format string
  1215.   is empty, the value is formatted using general floating-point formatting
  1216.   with 15 significant digits, corresponding to a call to FloatToStrF with
  1217.   the ffGeneral format. General floating-point formatting is also used if
  1218.   the value has more than 18 digits to the left of the decimal point and
  1219.   the format string does not specify scientific notation.
  1220.  
  1221.   The table below shows some sample formats and the results produced when
  1222.   the formats are applied to different values:
  1223.  
  1224.   Format string          1234        -1234       0.5         0
  1225.   -----------------------------------------------------------------------
  1226.                          1234        -1234       0.5         0
  1227.   0                      1234        -1234       1           0
  1228.   0.00                   1234.00     -1234.00    0.50        0.00
  1229.   #.##                   1234        -1234       .5
  1230.   #,##0.00               1,234.00    -1,234.00   0.50        0.00
  1231.   #,##0.00;(#,##0.00)    1,234.00    (1,234.00)  0.50        0.00
  1232.   #,##0.00;;Zero         1,234.00    -1,234.00   0.50        Zero
  1233.   0.000E+00              1.234E+03   -1.234E+03  5.000E-01   0.000E+00
  1234.   #.###E-0               1.234E3     -1.234E3    5E-1        0E0
  1235.   ----------------------------------------------------------------------- }
  1236.  
  1237. function FormatFloat(const Format: string; Value: Extended): string;
  1238.  
  1239. { FormatCurr formats the currency value given by Value using the format
  1240.   string given by Format. For further details, see the description of the
  1241.   FormatFloat function. }
  1242.  
  1243. function FormatCurr(const Format: string; Value: Currency): string;
  1244.  
  1245. { FloatToTextFmt converts the given floating-point value to its decimal
  1246.   representation using the specified format. The Value parameter must be a
  1247.   variable of type Extended or Currency, as indicated by the ValueType
  1248.   parameter. The resulting string of characters is stored in the given
  1249.   buffer, and the returned value is the number of characters stored. The
  1250.   resulting string is not null-terminated. For further details, see the
  1251.   description of the FormatFloat function. }
  1252.  
  1253. function FloatToTextFmt(Buffer: PChar; const Value; ValueType: TFloatValue;
  1254.   Format: PChar): Integer;
  1255.  
  1256. { StrToFloat converts the given string to a floating-point value. The string
  1257.   must consist of an optional sign (+ or -), a string of digits with an
  1258.   optional decimal point, and an optional 'E' or 'e' followed by a signed
  1259.   integer. Leading and trailing blanks in the string are ignored. The
  1260.   DecimalSeparator global variable defines the character that must be used
  1261.   as a decimal point. Thousand separators and currency symbols are not
  1262.   allowed in the string. If the string doesn't contain a valid value, an
  1263.   EConvertError exception is raised. }
  1264.  
  1265. function StrToFloat(const S: string): Extended;
  1266.  
  1267. { StrToCurr converts the given string to a currency value. For further
  1268.   details, see the description of the StrToFloat function. }
  1269.  
  1270. function StrToCurr(const S: string): Currency;
  1271.  
  1272. { TextToFloat converts the null-terminated string given by Buffer to a
  1273.   floating-point value which is returned in the variable given by Value.
  1274.   The Value parameter must be a variable of type Extended or Currency, as
  1275.   indicated by the ValueType parameter. The return value is True if the
  1276.   conversion was successful, or False if the string is not a valid
  1277.   floating-point value. For further details, see the description of the
  1278.   StrToFloat function. }
  1279.  
  1280. function TextToFloat(Buffer: PChar; var Value;
  1281.   ValueType: TFloatValue): Boolean;
  1282.  
  1283. { FloatToDecimal converts a floating-point value to a decimal representation
  1284.   that is suited for further formatting. The Value parameter must be a
  1285.   variable of type Extended or Currency, as indicated by the ValueType
  1286.   parameter. For values of type Extended, the Precision parameter specifies
  1287.   the requested number of significant digits in the result--the allowed range
  1288.   is 1..18. For values of type Currency, the Precision parameter is ignored,
  1289.   and the implied precision of the conversion is 19 digits. The Decimals
  1290.   parameter specifies the requested maximum number of digits to the left of
  1291.   the decimal point in the result. Precision and Decimals together control
  1292.   how the result is rounded. To produce a result that always has a given
  1293.   number of significant digits regardless of the magnitude of the number,
  1294.   specify 9999 for the Decimals parameter. The result of the conversion is
  1295.   stored in the specified TFloatRec record as follows:
  1296.  
  1297.   Exponent - Contains the magnitude of the number, i.e. the number of
  1298.   significant digits to the right of the decimal point. The Exponent field
  1299.   is negative if the absolute value of the number is less than one. If the
  1300.   number is a NAN (not-a-number), Exponent is set to -32768. If the number
  1301.   is INF or -INF (positive or negative infinity), Exponent is set to 32767.
  1302.  
  1303.   Negative - True if the number is negative, False if the number is zero
  1304.   or positive.
  1305.  
  1306.   Digits - Contains up to 18 (for type Extended) or 19 (for type Currency)
  1307.   significant digits followed by a null terminator. The implied decimal
  1308.   point (if any) is not stored in Digits. Trailing zeros are removed, and
  1309.   if the resulting number is zero, NAN, or INF, Digits contains nothing but
  1310.   the null terminator. }
  1311.  
  1312. procedure FloatToDecimal(var Result: TFloatRec; const Value;
  1313.   ValueType: TFloatValue; Precision, Decimals: Integer);
  1314.  
  1315. { Date/time support routines }
  1316.  
  1317. function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  1318.  
  1319. function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  1320. function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  1321. function TimeStampToMSecs(const TimeStamp: TTimeStamp): Comp;
  1322.  
  1323. { EncodeDate encodes the given year, month, and day into a TDateTime value.
  1324.   The year must be between 1 and 9999, the month must be between 1 and 12,
  1325.   and the day must be between 1 and N, where N is the number of days in the
  1326.   specified month. If the specified values are not within range, an
  1327.   EConvertError exception is raised. The resulting value is the number of
  1328.   days between 12/30/1899 and the given date. }
  1329.  
  1330. function EncodeDate(Year, Month, Day: Word): TDateTime;
  1331.  
  1332. { EncodeTime encodes the given hour, minute, second, and millisecond into a
  1333.   TDateTime value. The hour must be between 0 and 23, the minute must be
  1334.   between 0 and 59, the second must be between 0 and 59, and the millisecond
  1335.   must be between 0 and 999. If the specified values are not within range, an
  1336.   EConvertError exception is raised. The resulting value is a number between
  1337.   0 (inclusive) and 1 (not inclusive) that indicates the fractional part of
  1338.   a day given by the specified time. The value 0 corresponds to midnight,
  1339.   0.5 corresponds to noon, 0.75 corresponds to 6:00 pm, etc. }
  1340.  
  1341. function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
  1342.  
  1343. { DecodeDate decodes the integral (date) part of the given TDateTime value
  1344.   into its corresponding year, month, and day. If the given TDateTime value
  1345.   is less than or equal to zero, the year, month, and day return parameters
  1346.   are all set to zero. }
  1347.  
  1348. procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
  1349.  
  1350. { DecodeTime decodes the fractional (time) part of the given TDateTime value
  1351.   into its corresponding hour, minute, second, and millisecond. }
  1352.  
  1353. procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
  1354.  
  1355. { DayOfWeek returns the day of the week of the given date. The result is an
  1356.   integer between 1 and 7, corresponding to Sunday through Saturday. }
  1357.  
  1358. function DayOfWeek(Date: TDateTime): Integer;
  1359.  
  1360. { Date returns the current date. }
  1361.  
  1362. function Date: TDateTime;
  1363.  
  1364. { Time returns the current time. }
  1365.  
  1366. function Time: TDateTime;
  1367.  
  1368. { Now returns the current date and time, corresponding to Date + Time. }
  1369.  
  1370. function Now: TDateTime;
  1371.  
  1372. { DateToStr converts the date part of the given TDateTime value to a string.
  1373.   The conversion uses the format specified by the ShortDateFormat global
  1374.   variable. }
  1375.  
  1376. function DateToStr(Date: TDateTime): string;
  1377.  
  1378. { TimeToStr converts the time part of the given TDateTime value to a string.
  1379.   The conversion uses the format specified by the LongTimeFormat global
  1380.   variable. }
  1381.  
  1382. function TimeToStr(Time: TDateTime): string;
  1383.  
  1384. { DateTimeToStr converts the given date and time to a string. The resulting
  1385.   string consists of a date and time formatted using the ShortDateFormat and
  1386.   LongTimeFormat global variables. Time information is included in the
  1387.   resulting string only if the fractional part of the given date and time
  1388.   value is non-zero. }
  1389.  
  1390. function DateTimeToStr(DateTime: TDateTime): string;
  1391.  
  1392. { StrToDate converts the given string to a date value. The string must
  1393.   consist of two or three numbers, separated by the character defined by
  1394.   the DateSeparator global variable. The order for month, day, and year is
  1395.   determined by the ShortDateFormat global variable--possible combinations
  1396.   are m/d/y, d/m/y, and y/m/d. If the string contains only two numbers, it
  1397.   is interpreted as a date (m/d or d/m) in the current year. Year values
  1398.   between 0 and 99 are assumed to be in the current century. If the given
  1399.   string does not contain a valid date, an EConvertError exception is
  1400.   raised. }
  1401.  
  1402. function StrToDate(const S: string): TDateTime;
  1403.  
  1404. { StrToTime converts the given string to a time value. The string must
  1405.   consist of two or three numbers, separated by the character defined by
  1406.   the TimeSeparator global variable, optionally followed by an AM or PM
  1407.   indicator. The numbers represent hour, minute, and (optionally) second,
  1408.   in that order. If the time is followed by AM or PM, it is assumed to be
  1409.   in 12-hour clock format. If no AM or PM indicator is included, the time
  1410.   is assumed to be in 24-hour clock format. If the given string does not
  1411.   contain a valid time, an EConvertError exception is raised. }
  1412.  
  1413. function StrToTime(const S: string): TDateTime;
  1414.  
  1415. { StrToDateTime converts the given string to a date and time value. The
  1416.   string must contain a date optionally followed by a time. The date and
  1417.   time parts of the string must follow the formats described for the
  1418.   StrToDate and StrToTime functions. }
  1419.  
  1420. function StrToDateTime(const S: string): TDateTime;
  1421.  
  1422. { FormatDateTime formats the date-and-time value given by DateTime using the
  1423.   format given by Format. The following format specifiers are supported:
  1424.  
  1425.   c       Displays the date using the format given by the ShortDateFormat
  1426.           global variable, followed by the time using the format given by
  1427.           the LongTimeFormat global variable. The time is not displayed if
  1428.           the fractional part of the DateTime value is zero.
  1429.  
  1430.   d       Displays the day as a number without a leading zero (1-31).
  1431.  
  1432.   dd      Displays the day as a number with a leading zero (01-31).
  1433.  
  1434.   ddd     Displays the day as an abbreviation (Sun-Sat) using the strings
  1435.           given by the ShortDayNames global variable.
  1436.  
  1437.   dddd    Displays the day as a full name (Sunday-Saturday) using the strings
  1438.           given by the LongDayNames global variable.
  1439.  
  1440.   ddddd   Displays the date using the format given by the ShortDateFormat
  1441.           global variable.
  1442.  
  1443.   dddddd  Displays the date using the format given by the LongDateFormat
  1444.           global variable.
  1445.  
  1446.   m       Displays the month as a number without a leading zero (1-12). If
  1447.           the m specifier immediately follows an h or hh specifier, the
  1448.           minute rather than the month is displayed.
  1449.  
  1450.   mm      Displays the month as a number with a leading zero (01-12). If
  1451.           the mm specifier immediately follows an h or hh specifier, the
  1452.           minute rather than the month is displayed.
  1453.  
  1454.   mmm     Displays the month as an abbreviation (Jan-Dec) using the strings
  1455.           given by the ShortMonthNames global variable.
  1456.  
  1457.   mmmm    Displays the month as a full name (January-December) using the
  1458.           strings given by the LongMonthNames global variable.
  1459.  
  1460.   yy      Displays the year as a two-digit number (00-99).
  1461.  
  1462.   yyyy    Displays the year as a four-digit number (0000-9999).
  1463.  
  1464.   h       Displays the hour without a leading zero (0-23).
  1465.  
  1466.   hh      Displays the hour with a leading zero (00-23).
  1467.  
  1468.   n       Displays the minute without a leading zero (0-59).
  1469.  
  1470.   nn      Displays the minute with a leading zero (00-59).
  1471.  
  1472.   s       Displays the second without a leading zero (0-59).
  1473.  
  1474.   ss      Displays the second with a leading zero (00-59).
  1475.  
  1476.   t       Displays the time using the format given by the ShortTimeFormat
  1477.           global variable.
  1478.  
  1479.   tt      Displays the time using the format given by the LongTimeFormat
  1480.           global variable.
  1481.  
  1482.   am/pm   Uses the 12-hour clock for the preceding h or hh specifier, and
  1483.           displays 'am' for any hour before noon, and 'pm' for any hour
  1484.           after noon. The am/pm specifier can use lower, upper, or mixed
  1485.           case, and the result is displayed accordingly.
  1486.  
  1487.   a/p     Uses the 12-hour clock for the preceding h or hh specifier, and
  1488.           displays 'a' for any hour before noon, and 'p' for any hour after
  1489.           noon. The a/p specifier can use lower, upper, or mixed case, and
  1490.           the result is displayed accordingly.
  1491.  
  1492.   ampm    Uses the 12-hour clock for the preceding h or hh specifier, and
  1493.           displays the contents of the TimeAMString global variable for any
  1494.           hour before noon, and the contents of the TimePMString global
  1495.           variable for any hour after noon.
  1496.  
  1497.   /       Displays the date separator character given by the DateSeparator
  1498.           global variable.
  1499.  
  1500.   :       Displays the time separator character given by the TimeSeparator
  1501.           global variable.
  1502.  
  1503.   'xx'    Characters enclosed in single or double quotes are displayed as-is,
  1504.   "xx"    and do not affect formatting.
  1505.  
  1506.   Format specifiers may be written in upper case as well as in lower case
  1507.   letters--both produce the same result.
  1508.  
  1509.   If the string given by the Format parameter is empty, the date and time
  1510.   value is formatted as if a 'c' format specifier had been given.
  1511.  
  1512.   The following example:
  1513.  
  1514.     S := FormatDateTime('"The meeting is on" dddd, mmmm d, yyyy, ' +
  1515.       '"at" hh:mm AM/PM', StrToDateTime('2/15/95 10:30am'));
  1516.  
  1517.   assigns 'The meeting is on Wednesday, February 15, 1995 at 10:30 AM' to
  1518.   the string variable S. }
  1519.  
  1520. function FormatDateTime(const Format: string; DateTime: TDateTime): string;
  1521.  
  1522. { DateTimeToString converts the date and time value given by DateTime using
  1523.   the format string given by Format into the string variable given by Result.
  1524.   For further details, see the description of the FormatDateTime function. }
  1525.  
  1526. procedure DateTimeToString(var Result: string; const Format: string;
  1527.   DateTime: TDateTime);
  1528.  
  1529. { System error messages }
  1530.  
  1531. function SysErrorMessage(ErrorCode: Integer): string;
  1532.  
  1533. { Initialization file support }
  1534.  
  1535. function GetLocaleStr(Locale, LocaleType: Integer; const Default: string): string;
  1536. function GetLocaleChar(Locale, LocaleType: Integer; Default: Char): Char;
  1537.  
  1538. { GetFormatSettings resets all date and number format variables to their
  1539.   default values. }
  1540.  
  1541. procedure GetFormatSettings;
  1542.  
  1543. { Exception handling routines }
  1544.  
  1545. function ExceptObject: TObject;
  1546. function ExceptAddr: Pointer;
  1547.  
  1548. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  1549.  
  1550. procedure Abort;
  1551.  
  1552. procedure OutOfMemoryError;
  1553.  
  1554. procedure Beep;
  1555.  
  1556. implementation
  1557.