home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 48 / SENT14D.ISO / tech / delphi / disk14 / doc.pak / SYSUTILS.INT < prev    next >
Encoding:
Text File  |  1995-08-24  |  59.2 KB  |  1,407 lines

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