/system/SysUtils.pas
Pascal | 7353 lines | 5361 code | 720 blank | 1272 comment | 251 complexity | c3c097ab7d04c23510daba3f38a1c590 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
-
- {*******************************************************}
- { }
- { Borland Delphi Runtime Library }
- { System Utilities Unit }
- { }
- { Copyright (C) 1995,99 Inprise Corporation }
- { }
- {*******************************************************}
-
- unit SysUtils;
-
- {$H+}
-
- interface
-
- uses Windows, SysConst, kol;
-
- const
-
- { File open modes }
-
- fmOpenRead = $0000;
- fmOpenWrite = $0001;
- fmOpenReadWrite = $0002;
- fmShareCompat = $0000;
- fmShareExclusive = $0010;
- fmShareDenyWrite = $0020;
- fmShareDenyRead = $0030;
- fmShareDenyNone = $0040;
-
- { File attribute constants }
-
- faReadOnly = $00000001;
- faHidden = $00000002;
- faSysFile = $00000004;
- faVolumeID = $00000008;
- faDirectory = $00000010;
- faArchive = $00000020;
- faAnyFile = $0000003F;
-
- { File mode magic numbers }
-
- fmClosed = $D7B0;
- fmInput = $D7B1;
- fmOutput = $D7B2;
- fmInOut = $D7B3;
-
- { Seconds and milliseconds per day }
-
- SecsPerDay = 24 * 60 * 60;
- MSecsPerDay = SecsPerDay * 1000;
-
- { Days between 1/1/0001 and 12/31/1899 }
-
- DateDelta = 693594;
-
- type
-
- { Standard Character set type }
-
- TSysCharSet = set of Char;
-
- { Set access to an integer }
-
- TIntegerSet = set of 0..SizeOf(Integer) * 8 - 1;
-
- { Type conversion records }
-
- WordRec = packed record
- Lo, Hi: Byte;
- end;
-
- LongRec = packed record
- Lo, Hi: Word;
- end;
-
- Int64Rec = packed record
- Lo, Hi: DWORD;
- end;
-
- TMethod = record
- Code, Data: Pointer;
- end;
-
- { General arrays }
-
- PByteArray = ^TByteArray;
- TByteArray = array[0..32767] of Byte;
-
- PWordArray = ^TWordArray;
- TWordArray = array[0..16383] of Word;
-
- { Generic procedure pointer }
-
- TProcedure = procedure;
-
- { Generic filename type }
-
- TFileName = type string;
-
- { Search record used by FindFirst, FindNext, and FindClose }
-
- TSearchRec = record
- Time: Integer;
- Size: Integer;
- Attr: Integer;
- Name: TFileName;
- ExcludeAttr: Integer;
- FindHandle: THandle;
- FindData: TWin32FindData;
- end;
-
- { Typed-file and untyped-file record }
-
- TFileRec = packed record (* must match the size the compiler generates: 332 bytes *)
- Handle: Integer;
- Mode: Integer;
- RecSize: Cardinal;
- Private: array[1..28] of Byte;
- UserData: array[1..32] of Byte;
- Name: array[0..259] of Char;
- end;
-
- { Text file record structure used for Text files }
-
- PTextBuf = ^TTextBuf;
- TTextBuf = array[0..127] of Char;
- TTextRec = packed record (* must match the size the compiler generates: 460 bytes *)
- Handle: Integer;
- Mode: Integer;
- BufSize: Cardinal;
- BufPos: Cardinal;
- BufEnd: Cardinal;
- BufPtr: PChar;
- OpenFunc: Pointer;
- InOutFunc: Pointer;
- FlushFunc: Pointer;
- CloseFunc: Pointer;
- UserData: array[1..32] of Byte;
- Name: array[0..259] of Char;
- Buffer: TTextBuf;
- end;
-
- { FloatToText, FloatToTextFmt, TextToFloat, and FloatToDecimal type codes }
-
- TFloatValue = (fvExtended, fvCurrency);
-
- { FloatToText format codes }
-
- TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
-
- { FloatToDecimal result record }
-
- TFloatRec = packed record
- Exponent: Smallint;
- Negative: Boolean;
- Digits: array[0..20] of Char;
- end;
-
- { Date and time record }
-
- TTimeStamp = record
- Time: Integer; { Number of milliseconds since midnight }
- Date: Integer; { One plus number of days since 1/1/0001 }
- end;
-
- { MultiByte Character Set (MBCS) byte type }
- TMbcsByteType = (mbSingleByte, mbLeadByte, mbTrailByte);
-
- { System Locale information record }
- TSysLocale = packed record
- DefaultLCID: LCID;
- PriLangID: LANGID;
- SubLangID: LANGID;
- FarEast: Boolean;
- MiddleEast: Boolean;
- end;
-
- { This is used by TLanguages }
- TLangRec = packed record
- FName: string;
- FLCID: LCID;
- FExt: string;
- end;
-
- { This stores the langauges that the system supports }
- TLanguages = class
- private
- FSysLangs: array of TLangRec;
- function LocalesCallback(LocaleID: PChar): Integer; stdcall;
- function GetExt(Index: Integer): string;
- function GetID(Index: Integer): string;
- function GetLCID(Index: Integer): LCID;
- function GetName(Index: Integer): string;
- function GetNameFromLocaleID(ID: LCID): string;
- function GetNameFromLCID(const ID: string): string;
- function GetCount: integer;
- public
- constructor Create;
- function IndexOf(ID: LCID): Integer;
- property Count: Integer read GetCount;
- property Name[Index: Integer]: string read GetName;
- property NameFromLocaleID[ID: LCID]: string read GetNameFromLocaleID;
- property NameFromLCID[const ID: string]: string read GetNameFromLCID;
- property ID[Index: Integer]: string read GetID;
- property LocaleID[Index: Integer]: LCID read GetLCID;
- property Ext[Index: Integer]: string read GetExt;
- end;
-
- { Exceptions }
-
- Exception = class(TObject)
- private
- FMessage: string;
- FHelpContext: Integer;
- public
- constructor Create(const Msg: string);
- constructor CreateFmt(const Msg: string; const Args: array of const);
- constructor CreateRes(Ident: Integer); overload;
- constructor CreateRes(ResStringRec: PResStringRec); overload;
- constructor CreateResFmt(Ident: Integer; const Args: array of const); overload;
- constructor CreateResFmt(ResStringRec: PResStringRec; const Args: array of const); overload;
- constructor CreateHelp(const Msg: string; AHelpContext: Integer);
- constructor CreateFmtHelp(const Msg: string; const Args: array of const;
- AHelpContext: Integer);
- constructor CreateResHelp(Ident: Integer; AHelpContext: Integer); overload;
- constructor CreateResHelp(ResStringRec: PResStringRec; AHelpContext: Integer); overload;
- constructor CreateResFmtHelp(ResStringRec: PResStringRec; const Args: array of const;
- AHelpContext: Integer); overload;
- constructor CreateResFmtHelp(Ident: Integer; const Args: array of const;
- AHelpContext: Integer); overload;
- property HelpContext: Integer read FHelpContext write FHelpContext;
- property Message: string read FMessage write FMessage;
- end;
-
- ExceptClass = class of Exception;
-
- EAbort = class(Exception);
-
- EHeapException = class(Exception)
- private
- AllowFree: Boolean;
- public
- procedure FreeInstance; override;
- end;
-
- EOutOfMemory = class(EHeapException);
-
- EInOutError = class(Exception)
- public
- ErrorCode: Integer;
- end;
-
- EExternal = class(Exception)
- public
- ExceptionRecord: PExceptionRecord;
- end;
-
- EExternalException = class(EExternal);
-
- EIntError = class(EExternal);
- EDivByZero = class(EIntError);
- ERangeError = class(EIntError);
- EIntOverflow = class(EIntError);
-
- EMathError = class(EExternal);
- EInvalidOp = class(EMathError);
- EZeroDivide = class(EMathError);
- EOverflow = class(EMathError);
- EUnderflow = class(EMathError);
-
- EInvalidPointer = class(EHeapException);
-
- EInvalidCast = class(Exception);
-
- EConvertError = class(Exception);
-
- EAccessViolation = class(EExternal);
- EPrivilege = class(EExternal);
- EStackOverflow = class(EExternal);
- EControlC = class(EExternal);
-
- EVariantError = class(Exception);
-
- EPropReadOnly = class(Exception);
- EPropWriteOnly = class(Exception);
-
- EAssertionFailed = class(Exception);
-
- EAbstractError = class(Exception);
-
- EIntfCastError = class(Exception);
-
- EInvalidContainer = class(Exception);
- EInvalidInsert = class(Exception);
-
- EPackageError = class(Exception);
-
- EWin32Error = class(Exception)
- public
- ErrorCode: DWORD;
- end;
-
- ESafecallException = class(Exception);
-
- var
-
- { Empty string and null string pointer. These constants are provided for
- backwards compatibility only. }
-
- EmptyStr: string = '';
- NullStr: PString = @EmptyStr;
-
- { Win32 platform identifier. This will be one of the following values:
-
- VER_PLATFORM_WIN32s
- VER_PLATFORM_WIN32_WINDOWS
- VER_PLATFORM_WIN32_NT
-
- See WINDOWS.PAS for the numerical values. }
-
- Win32Platform: Integer = 0;
-
- { Win32 OS version information -
-
- see TOSVersionInfo.dwMajorVersion/dwMinorVersion/dwBuildNumber }
-
- Win32MajorVersion: Integer = 0;
- Win32MinorVersion: Integer = 0;
- Win32BuildNumber: Integer = 0;
-
- { Win32 OS extra version info string -
-
- see TOSVersionInfo.szCSDVersion }
-
- Win32CSDVersion: string = '';
-
- { Currency and date/time formatting options
-
- The initial values of these variables are fetched from the system registry
- using the GetLocaleInfo function in the Win32 API. The description of each
- variable specifies the LOCALE_XXXX constant used to fetch the initial
- value.
-
- CurrencyString - Defines the currency symbol used in floating-point to
- decimal conversions. The initial value is fetched from LOCALE_SCURRENCY.
-
- CurrencyFormat - Defines the currency symbol placement and separation
- used in floating-point to decimal conversions. Possible values are:
-
- 0 = '$1'
- 1 = '1$'
- 2 = '$ 1'
- 3 = '1 $'
-
- The initial value is fetched from LOCALE_ICURRENCY.
-
- NegCurrFormat - Defines the currency format for used in floating-point to
- decimal conversions of negative numbers. Possible values are:
-
- 0 = '($1)' 4 = '(1$)' 8 = '-1 $' 12 = '$ -1'
- 1 = '-$1' 5 = '-1$' 9 = '-$ 1' 13 = '1- $'
- 2 = '$-1' 6 = '1-$' 10 = '1 $-' 14 = '($ 1)'
- 3 = '$1-' 7 = '1$-' 11 = '$ 1-' 15 = '(1 $)'
-
- The initial value is fetched from LOCALE_INEGCURR.
-
- ThousandSeparator - The character used to separate thousands in numbers
- with more than three digits to the left of the decimal separator. The
- initial value is fetched from LOCALE_STHOUSAND.
-
- DecimalSeparator - The character used to separate the integer part from
- the fractional part of a number. The initial value is fetched from
- LOCALE_SDECIMAL.
-
- CurrencyDecimals - The number of digits to the right of the decimal point
- in a currency amount. The initial value is fetched from LOCALE_ICURRDIGITS.
-
- DateSeparator - The character used to separate the year, month, and day
- parts of a date value. The initial value is fetched from LOCATE_SDATE.
-
- ShortDateFormat - The format string used to convert a date value to a
- short string suitable for editing. For a complete description of date and
- time format strings, refer to the documentation for the FormatDate
- function. The short date format should only use the date separator
- character and the m, mm, d, dd, yy, and yyyy format specifiers. The
- initial value is fetched from LOCALE_SSHORTDATE.
-
- LongDateFormat - The format string used to convert a date value to a long
- string suitable for display but not for editing. For a complete description
- of date and time format strings, refer to the documentation for the
- FormatDate function. The initial value is fetched from LOCALE_SLONGDATE.
-
- TimeSeparator - The character used to separate the hour, minute, and
- second parts of a time value. The initial value is fetched from
- LOCALE_STIME.
-
- TimeAMString - The suffix string used for time values between 00:00 and
- 11:59 in 12-hour clock format. The initial value is fetched from
- LOCALE_S1159.
-
- TimePMString - The suffix string used for time values between 12:00 and
- 23:59 in 12-hour clock format. The initial value is fetched from
- LOCALE_S2359.
-
- ShortTimeFormat - The format string used to convert a time value to a
- short string with only hours and minutes. The default value is computed
- from LOCALE_ITIME and LOCALE_ITLZERO.
-
- LongTimeFormat - The format string used to convert a time value to a long
- string with hours, minutes, and seconds. The default value is computed
- from LOCALE_ITIME and LOCALE_ITLZERO.
-
- ShortMonthNames - Array of strings containing short month names. The mmm
- format specifier in a format string passed to FormatDate causes a short
- month name to be substituted. The default values are fecthed from the
- LOCALE_SABBREVMONTHNAME system locale entries.
-
- LongMonthNames - Array of strings containing long month names. The mmmm
- format specifier in a format string passed to FormatDate causes a long
- month name to be substituted. The default values are fecthed from the
- LOCALE_SMONTHNAME system locale entries.
-
- ShortDayNames - Array of strings containing short day names. The ddd
- format specifier in a format string passed to FormatDate causes a short
- day name to be substituted. The default values are fecthed from the
- LOCALE_SABBREVDAYNAME system locale entries.
-
- LongDayNames - Array of strings containing long day names. The dddd
- format specifier in a format string passed to FormatDate causes a long
- day name to be substituted. The default values are fecthed from the
- LOCALE_SDAYNAME system locale entries.
-
- ListSeparator - The character used to separate items in a list. The
- initial value is fetched from LOCALE_SLIST.
-
- TwoDigitYearCenturyWindow - Determines what century is added to two
- digit years when converting string dates to numeric dates. This value
- is subtracted from the current year before extracting the century.
- This can be used to extend the lifetime of existing applications that
- are inextricably tied to 2 digit year data entry. The best solution
- to Year 2000 (Y2k) issues is not to accept 2 digit years at all - require
- 4 digit years in data entry to eliminate century ambiguities.
-
- Examples:
-
- Current TwoDigitCenturyWindow Century StrToDate() of:
- Year Value Pivot '01/01/03' '01/01/68' '01/01/50'
- -------------------------------------------------------------------------
- 1998 0 1900 1903 1968 1950
- 2002 0 2000 2003 2068 2050
- 1998 50 (default) 1948 2003 1968 1950
- 2002 50 (default) 1952 2003 1968 2050
- 2020 50 (default) 1970 2003 2068 2050
- }
-
- var
- CurrencyString: string;
- CurrencyFormat: Byte;
- NegCurrFormat: Byte;
- ThousandSeparator: Char;
- DecimalSeparator: Char;
- CurrencyDecimals: Byte;
- DateSeparator: Char;
- ShortDateFormat: string;
- LongDateFormat: string;
- TimeSeparator: Char;
- TimeAMString: string;
- TimePMString: string;
- ShortTimeFormat: string;
- LongTimeFormat: string;
- ShortMonthNames: array[1..12] of string;
- LongMonthNames: array[1..12] of string;
- ShortDayNames: array[1..7] of string;
- LongDayNames: array[1..7] of string;
- SysLocale: TSysLocale;
- EraNames: array[1..7] of string;
- EraYearOffsets: array[1..7] of Integer;
- TwoDigitYearCenturyWindow: Word = 50;
- ListSeparator: Char;
-
- function Languages: TLanguages;
-
- { Memory management routines }
-
- { AllocMem allocates a block of the given size on the heap. Each byte in
- the allocated buffer is set to zero. To dispose the buffer, use the
- FreeMem standard procedure. }
-
- function AllocMem(Size: Cardinal): Pointer;
-
- { Exit procedure handling }
-
- { AddExitProc adds the given procedure to the run-time library's exit
- procedure list. When an application terminates, its exit procedures are
- executed in reverse order of definition, i.e. the last procedure passed
- to AddExitProc is the first one to get executed upon termination. }
-
- procedure AddExitProc(Proc: TProcedure);
-
- { String handling routines }
-
- { NewStr allocates a string on the heap. NewStr is provided for backwards
- compatibility only. }
-
- function NewStr(const S: string): PString;
-
- { DisposeStr disposes a string pointer that was previously allocated using
- NewStr. DisposeStr is provided for backwards compatibility only. }
-
- procedure DisposeStr(P: PString);
-
- { AssignStr assigns a new dynamically allocated string to the given string
- pointer. AssignStr is provided for backwards compatibility only. }
-
- procedure AssignStr(var P: PString; const S: string);
-
- { AppendStr appends S to the end of Dest. AppendStr is provided for
- backwards compatibility only. Use "Dest := Dest + S" instead. }
-
- procedure AppendStr(var Dest: string; const S: string);
-
- { UpperCase converts all ASCII characters in the given string to upper case.
- The conversion affects only 7-bit ASCII characters between 'a' and 'z'. To
- convert 8-bit international characters, use AnsiUpperCase. }
-
- function UpperCase(const S: string): string;
-
- { LowerCase converts all ASCII characters in the given string to lower case.
- The conversion affects only 7-bit ASCII characters between 'A' and 'Z'. To
- convert 8-bit international characters, use AnsiLowerCase. }
-
- function LowerCase(const S: string): string;
-
- { CompareStr compares S1 to S2, with case-sensitivity. The return value is
- less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2. The
- compare operation is based on the 8-bit ordinal value of each character
- and is not affected by the current Windows locale. }
-
- function CompareStr(const S1, S2: string): Integer;
-
- { CompareMem performs a binary compare of Length bytes of memory referenced
- by P1 to that of P2. CompareMem returns True if the memory referenced by
- P1 is identical to that of P2. }
-
- function CompareMem(P1, P2: Pointer; Length: Integer): Boolean; assembler;
-
- { CompareText compares S1 to S2, without case-sensitivity. The return value
- is the same as for CompareStr. The compare operation is based on the 8-bit
- ordinal value of each character, after converting 'a'..'z' to 'A'..'Z',
- and is not affected by the current Windows locale. }
-
- function CompareText(const S1, S2: string): Integer;
-
- { SameText compares S1 to S2, without case-sensitivity. Returns true if
- S1 and S2 are the equal, that is, if CompareText would return 0. SameText
- has the same 8-bit limitations as CompareText }
-
- function SameText(const S1, S2: string): Boolean;
-
- { AnsiUpperCase converts all characters in the given string to upper case.
- The conversion uses the current Windows locale. }
-
- function AnsiUpperCase(const S: string): string;
-
- { AnsiLowerCase converts all characters in the given string to lower case.
- The conversion uses the current Windows locale. }
-
- function AnsiLowerCase(const S: string): string;
-
- { AnsiCompareStr compares S1 to S2, with case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is the same as for CompareStr. }
-
- function AnsiCompareStr(const S1, S2: string): Integer;
-
- { AnsiSameStr compares S1 to S2, with case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is True if AnsiCompareStr would have returned 0. }
-
- function AnsiSameStr(const S1, S2: string): Boolean;
-
- { AnsiCompareText compares S1 to S2, without case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is the same as for CompareStr. }
-
- function AnsiCompareText(const S1, S2: string): Integer;
-
- { AnsiSameText compares S1 to S2, without case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is True if AnsiCompareText would have returned 0. }
-
- function AnsiSameText(const S1, S2: string): Boolean;
-
- { AnsiStrComp compares S1 to S2, with case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is the same as for CompareStr. }
-
- function AnsiStrComp(S1, S2: PChar): Integer;
-
- { AnsiStrIComp compares S1 to S2, without case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is the same as for CompareStr. }
-
- function AnsiStrIComp(S1, S2: PChar): Integer;
-
- { AnsiStrLComp compares S1 to S2, with case-sensitivity, up to a maximum
- length of MaxLen bytes. The compare operation is controlled by the
- current Windows locale. The return value is the same as for CompareStr. }
-
- function AnsiStrLComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
-
- { AnsiStrLIComp compares S1 to S2, without case-sensitivity, up to a maximum
- length of MaxLen bytes. The compare operation is controlled by the
- current Windows locale. The return value is the same as for CompareStr. }
-
- function AnsiStrLIComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
-
- { AnsiStrLower converts all characters in the given string to lower case.
- The conversion uses the current Windows locale. }
-
- function AnsiStrLower(Str: PChar): PChar;
-
- { AnsiStrUpper converts all characters in the given string to upper case.
- The conversion uses the current Windows locale. }
-
- function AnsiStrUpper(Str: PChar): PChar;
-
- { AnsiLastChar returns a pointer to the last full character in the string.
- This function supports multibyte characters }
-
- function AnsiLastChar(const S: string): PChar;
-
- { AnsiStrLastChar returns a pointer to the last full character in the string.
- This function supports multibyte characters. }
-
- function AnsiStrLastChar(P: PChar): PChar;
-
- { Trim trims leading and trailing spaces and control characters from the
- given string. }
-
- function Trim(const S: string): string;
-
- { TrimLeft trims leading spaces and control characters from the given
- string. }
-
- function TrimLeft(const S: string): string;
-
- { TrimRight trims trailing spaces and control characters from the given
- string. }
-
- function TrimRight(const S: string): string;
-
- { QuotedStr returns the given string as a quoted string. A single quote
- character is inserted at the beginning and the end of the string, and
- for each single quote character in the string, another one is added. }
-
- function QuotedStr(const S: string): string;
-
- { AnsiQuotedStr returns the given string as a quoted string, using the
- provided Quote character. A Quote character is inserted at the beginning
- and end of thestring, and each Quote character in the string is doubled.
- This function supports multibyte character strings (MBCS). }
-
- function AnsiQuotedStr(const S: string; Quote: Char): string;
-
- { AnsiExtractQuotedStr removes the Quote characters from the beginning and end
- of a quoted string, and reduces pairs of Quote characters within the quoted
- string to a single character. If the first character in Src is not the Quote
- character, the function returns an empty string. The function copies
- characters from the Src to the result string until the second solitary
- Quote character or the first null character in Src. The Src parameter is
- updated to point to the first character following the quoted string. If
- the Src string does not contain a matching end Quote character, the Src
- parameter is updated to point to the terminating null character in Src.
- This function supports multibyte character strings (MBCS). }
-
- function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
-
- { AdjustLineBreaks adjusts all line breaks in the given string to be true
- CR/LF sequences. The function changes any CR characters not followed by
- a LF and any LF characters not preceded by a CR into CR/LF pairs. }
-
- function AdjustLineBreaks(const S: string): string;
-
- { IsValidIdent returns true if the given string is a valid identifier. An
- identifier is defined as a character from the set ['A'..'Z', 'a'..'z', '_']
- followed by zero or more characters from the set ['A'..'Z', 'a'..'z',
- '0..'9', '_']. }
-
- function IsValidIdent(const Ident: string): Boolean;
-
- { IntToStr converts the given value to its decimal string representation. }
-
- function IntToStr(Value: Integer): string; overload;
- function IntToStr(Value: Int64): string; overload;
-
- { IntToHex converts the given value to a hexadecimal string representation
- with the minimum number of digits specified. }
-
- function IntToHex(Value: Integer; Digits: Integer): string; overload;
- function IntToHex(Value: Int64; Digits: Integer): string; overload;
-
- { StrToInt converts the given string to an integer value. If the string
- doesn't contain a valid value, an EConvertError exception is raised. }
-
- function StrToInt(const S: string): Integer;
- function StrToInt64(const S: string): Int64;
-
- { StrToIntDef converts the given string to an integer value. If the string
- doesn't contain a valid value, the value given by Default is returned. }
-
- function StrToIntDef(const S: string; Default: Integer): Integer;
- function StrToInt64Def(const S: string; Default: Int64): Int64;
-
- { LoadStr loads the string resource given by Ident from the application's
- executable file. If the string resource does not exist, an empty string
- is returned. }
-
- function LoadStr(Ident: Integer): string;
-
- { LoadStr loads the string resource given by Ident from the application's
- executable file, and uses it as the format string in a call to the
- Format function with the given arguments. }
-
- function FmtLoadStr(Ident: Integer; const Args: array of const): string;
-
- { File management routines }
-
- { FileOpen opens the specified file using the specified access mode. The
- access mode value is constructed by OR-ing one of the fmOpenXXXX constants
- with one of the fmShareXXXX constants. If the return value is positive,
- the function was successful and the value is the file handle of the opened
- file. A return value of -1 indicates that an error occurred. }
-
- function FileOpen(const FileName: string; Mode: LongWord): Integer;
-
- { FileCreate creates a new file by the specified name. If the return value
- is positive, the function was successful and the value is the file handle
- of the new file. A return value of -1 indicates that an error occurred. }
-
- function FileCreate(const FileName: string): Integer;
-
- { FileRead reads Count bytes from the file given by Handle into the buffer
- specified by Buffer. The return value is the number of bytes actually
- read; it is less than Count if the end of the file was reached. The return
- value is -1 if an error occurred. }
-
- function FileRead(Handle: Integer; var Buffer; Count: LongWord): Integer;
-
- { FileWrite writes Count bytes to the file given by Handle from the buffer
- specified by Buffer. The return value is the number of bytes actually
- written, or -1 if an error occurred. }
-
- function FileWrite(Handle: Integer; const Buffer; Count: LongWord): Integer;
-
- { FileSeek changes the current position of the file given by Handle to be
- Offset bytes relative to the point given by Origin. Origin = 0 means that
- Offset is relative to the beginning of the file, Origin = 1 means that
- Offset is relative to the current position, and Origin = 2 means that
- Offset is relative to the end of the file. The return value is the new
- current position, relative to the beginning of the file, or -1 if an error
- occurred. }
-
- function FileSeek(Handle, Offset, Origin: Integer): Integer; overload;
- function FileSeek(Handle: Integer; const Offset: Int64; Origin: Integer): Int64; overload;
-
- { FileClose closes the specified file. }
-
- procedure FileClose(Handle: Integer);
-
- { FileAge returns the date-and-time stamp of the specified file. The return
- value can be converted to a TDateTime value using the FileDateToDateTime
- function. The return value is -1 if the file does not exist. }
-
- function FileAge(const FileName: string): Integer;
-
- { FileExists returns a boolean value that indicates whether the specified
- file exists. }
-
- function FileExists(const FileName: string): Boolean;
-
- { FindFirst searches the directory given by Path for the first entry that
- matches the filename given by Path and the attributes given by Attr. The
- result is returned in the search record given by SearchRec. The return
- value is zero if the function was successful. Otherwise the return value
- is a Windows error code. FindFirst is typically used in conjunction with
- FindNext and FindClose as follows:
-
- Result := FindFirst(Path, Attr, SearchRec);
- while Result = 0 do
- begin
- ProcessSearchRec(SearchRec);
- Result := FindNext(SearchRec);
- end;
- FindClose(SearchRec);
-
- where ProcessSearchRec represents user-defined code that processes the
- information in a search record. }
-
- function FindFirst(const Path: string; Attr: Integer;
- var F: TSearchRec): Integer;
-
- { FindNext returs the next entry that matches the name and attributes
- specified in a previous call to FindFirst. The search record must be one
- that was passed to FindFirst. The return value is zero if the function was
- successful. Otherwise the return value is a Windows error code. }
-
- function FindNext(var F: TSearchRec): Integer;
-
- { FindClose terminates a FindFirst/FindNext sequence. FindClose does nothing
- in the 16-bit version of Windows, but is required in the 32-bit version,
- so for maximum portability every FindFirst/FindNext sequence should end
- with a call to FindClose. }
-
- procedure FindClose(var F: TSearchRec);
-
- { FileGetDate returns the DOS date-and-time stamp of the file given by
- Handle. The return value is -1 if the handle is invalid. The
- FileDateToDateTime function can be used to convert the returned value to
- a TDateTime value. }
-
- function FileGetDate(Handle: Integer): Integer;
-
- { FileSetDate sets the DOS date-and-time stamp of the file given by Handle
- to the value given by Age. The DateTimeToFileDate function can be used to
- convert a TDateTime value to a DOS date-and-time stamp. The return value
- is zero if the function was successful. Otherwise the return value is a
- Windows error code. }
-
- function FileSetDate(Handle: Integer; Age: Integer): Integer;
-
- { FileGetAttr returns the file attributes of the file given by FileName. The
- attributes can be examined by AND-ing with the faXXXX constants defined
- above. A return value of -1 indicates that an error occurred. }
-
- function FileGetAttr(const FileName: string): Integer;
-
- { FileSetAttr sets the file attributes of the file given by FileName to the
- value given by Attr. The attribute value is formed by OR-ing the
- appropriate faXXXX constants. The return value is zero if the function was
- successful. Otherwise the return value is a Windows error code. }
-
- function FileSetAttr(const FileName: string; Attr: Integer): Integer;
-
- { DeleteFile deletes the file given by FileName. The return value is True if
- the file was successfully deleted, or False if an error occurred. }
-
- function DeleteFile(const FileName: string): Boolean;
-
- { RenameFile renames the file given by OldName to the name given by NewName.
- The return value is True if the file was successfully renamed, or False if
- an error occurred. }
-
- function RenameFile(const OldName, NewName: string): Boolean;
-
- { ChangeFileExt changes the extension of a filename. FileName specifies a
- filename with or without an extension, and Extension specifies the new
- extension for the filename. The new extension can be a an empty string or
- a period followed by up to three characters. }
-
- function ChangeFileExt(const FileName, Extension: string): string;
-
- { ExtractFilePath extracts the drive and directory parts of the given
- filename. The resulting string is the leftmost characters of FileName,
- up to and including the colon or backslash that separates the path
- information from the name and extension. The resulting string is empty
- if FileName contains no drive and directory parts. }
-
- function ExtractFilePath(const FileName: string): string;
-
- { ExtractFileDir extracts the drive and directory parts of the given
- filename. The resulting string is a directory name suitable for passing
- to SetCurrentDir, CreateDir, etc. The resulting string is empty if
- FileName contains no drive and directory parts. }
-
- function ExtractFileDir(const FileName: string): string;
-
- { ExtractFileDrive extracts the drive part of the given filename. For
- filenames with drive letters, the resulting string is '<drive>:'.
- For filenames with a UNC path, the resulting string is in the form
- '\\<servername>\<sharename>'. If the given path contains neither
- style of filename, the result is an empty string. }
-
- function ExtractFileDrive(const FileName: string): string;
-
- { ExtractFileName extracts the name and extension parts of the given
- filename. The resulting string is the leftmost characters of FileName,
- starting with the first character after the colon or backslash that
- separates the path information from the name and extension. The resulting
- string is equal to FileName if FileName contains no drive and directory
- parts. }
-
- function ExtractFileName(const FileName: string): string;
-
- { ExtractFileExt extracts the extension part of the given filename. The
- resulting string includes the period character that separates the name
- and extension parts. The resulting string is empty if the given filename
- has no extension. }
-
- function ExtractFileExt(const FileName: string): string;
-
- { ExpandFileName expands the given filename to a fully qualified filename.
- The resulting string consists of a drive letter, a colon, a root relative
- directory path, and a filename. Embedded '.' and '..' directory references
- are removed. }
-
- function ExpandFileName(const FileName: string): string;
-
- { ExpandUNCFileName expands the given filename to a fully qualified filename.
- This function is the same as ExpandFileName except that it will return the
- drive portion of the filename in the format '\\<servername>\<sharename> if
- that drive is actually a network resource instead of a local resource.
- Like ExpandFileName, embedded '.' and '..' directory references are
- removed. }
-
- function ExpandUNCFileName(const FileName: string): string;
-
- { ExtractRelativePath will return a file path name relative to the given
- BaseName. It strips the common path dirs and adds '..\' for each level
- up from the BaseName path. }
-
- function ExtractRelativePath(const BaseName, DestName: string): string;
-
- { ExtractShortPathName will convert the given filename to the short form
- by calling the GetShortPathName API. Will return an empty string if
- the file or directory specified does not exist }
-
- function ExtractShortPathName(const FileName: string): string;
-
- { FileSearch searches for the file given by Name in the list of directories
- given by DirList. The directory paths in DirList must be separated by
- semicolons. The search always starts with the current directory of the
- current drive. The returned value is a concatenation of one of the
- directory paths and the filename, or an empty string if the file could not
- be located. }
-
- function FileSearch(const Name, DirList: string): string;
-
- { DiskFree returns the number of free bytes on the specified drive number,
- where 0 = Current, 1 = A, 2 = B, etc. DiskFree returns -1 if the drive
- number is invalid. }
-
- function DiskFree(Drive: Byte): Int64;
-
- { DiskSize returns the size in bytes of the specified drive number, where
- 0 = Current, 1 = A, 2 = B, etc. DiskSize returns -1 if the drive number
- is invalid. }
-
- function DiskSize(Drive: Byte): Int64;
-
- { FileDateToDateTime converts a DOS date-and-time value to a TDateTime
- value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
- date-and-time values, and the Time field of a TSearchRec used by the
- FindFirst and FindNext functions contains a DOS date-and-time value. }
-
- function FileDateToDateTime(FileDate: Integer): TDateTime;
-
- { DateTimeToFileDate converts a TDateTime value to a DOS date-and-time
- value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
- date-and-time values, and the Time field of a TSearchRec used by the
- FindFirst and FindNext functions contains a DOS date-and-time value. }
-
- function DateTimeToFileDate(DateTime: TDateTime): Integer;
-
- { GetCurrentDir returns the current directory. }
-
- function GetCurrentDir: string;
-
- { SetCurrentDir sets the current directory. The return value is True if
- the current directory was successfully changed, or False if an error
- occurred. }
-
- function SetCurrentDir(const Dir: string): Boolean;
-
- { CreateDir creates a new directory. The return value is True if a new
- directory was successfully created, or False if an error occurred. }
-
- function CreateDir(const Dir: string): Boolean;
-
- { RemoveDir deletes an existing empty directory. The return value is
- True if the directory was successfully deleted, or False if an error
- occurred. }
-
- function RemoveDir(const Dir: string): Boolean;
-
- { PChar routines }
- { const params help simplify C++ code. No effect on pascal code }
-
- { StrLen returns the number of characters in Str, not counting the null
- terminator. }
-
- function StrLen(const Str: PChar): Cardinal;
-
- { StrEnd returns a pointer to the null character that terminates Str. }
-
- function StrEnd(const Str: PChar): PChar;
-
- { StrMove copies exactly Count characters from Source to Dest and returns
- Dest. Source and Dest may overlap. }
-
- function StrMove(Dest: PChar; const Source: PChar; Count: Cardinal): PChar;
-
- { StrCopy copies Source to Dest and returns Dest. }
-
- function StrCopy(Dest: PChar; const Source: PChar): PChar;
-
- { StrECopy copies Source to Dest and returns StrEnd(Dest). }
-
- function StrECopy(Dest:PChar; const Source: PChar): PChar;
-
- { StrLCopy copies at most MaxLen characters from Source to Dest and
- returns Dest. }
-
- function StrLCopy(Dest: PChar; const Source: PChar; MaxLen: Cardinal): PChar;
-
- { StrPCopy copies the Pascal style string Source into Dest and
- returns Dest. }
-
- function StrPCopy(Dest: PChar; const Source: string): PChar;
-
- { StrPLCopy copies at most MaxLen characters from the Pascal style string
- Source into Dest and returns Dest. }
-
- function StrPLCopy(Dest: PChar; const Source: string;
- MaxLen: Cardinal): PChar;
-
- { StrCat appends a copy of Source to the end of Dest and returns Dest. }
-
- function StrCat(Dest: PChar; const Source: PChar): PChar;
-
- { StrLCat appends at most MaxLen - StrLen(Dest) characters from Source to
- the end of Dest, and returns Dest. }
-
- function StrLCat(Dest: PChar; const Source: PChar; MaxLen: Cardinal): PChar;
-
- { StrComp compares Str1 to Str2. The return value is less than 0 if
- Str1 < Str2, 0 if Str1 = Str2, or greater than 0 if Str1 > Str2. }
-
- function StrComp(const Str1, Str2: PChar): Integer;
-
- { StrIComp compares Str1 to Str2, without case sensitivity. The return
- value is the same as StrComp. }
-
- function StrIComp(const Str1, Str2: PChar): Integer;
-
- { StrLComp compares Str1 to Str2, for a maximum length of MaxLen
- characters. The return value is the same as StrComp. }
-
- function StrLComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer;
-
- { StrLIComp compares Str1 to Str2, for a maximum length of MaxLen
- characters, without case sensitivity. The return value is the same
- as StrComp. }
-
- function StrLIComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer;
-
- { StrScan returns a pointer to the first occurrence of Chr in Str. If Chr
- does not occur in Str, StrScan returns NIL. The null terminator is
- considered to be part of the string. }
-
- function StrScan(const Str: PChar; Chr: Char): PChar;
-
- { StrRScan returns a pointer to the last occurrence of Chr in Str. If Chr
- does not occur in Str, StrRScan returns NIL. The null terminator is
- considered to be part of the string. }
-
- function StrRScan(const Str: PChar; Chr: Char): PChar;
-
- { StrPos returns a pointer to the first occurrence of Str2 in Str1. If
- Str2 does not occur in Str1, StrPos returns NIL. }
-
- function StrPos(const Str1, Str2: PChar): PChar;
-
- { StrUpper converts Str to upper case and returns Str. }
-
- function StrUpper(Str: PChar): PChar;
-
- { StrLower converts Str to lower case and returns Str. }
-
- function StrLower(Str: PChar): PChar;
-
- { StrPas converts Str to a Pascal style string. This function is provided
- for backwards compatibility only. To convert a null terminated string to
- a Pascal style string, use a string type cast or an assignment. }
-
- function StrPas(const Str: PChar): string;
-
- { StrAlloc allocates a buffer of the given size on the heap. The size of
- the allocated buffer is encoded in a four byte header that immediately
- preceeds the buffer. To dispose the buffer, use StrDispose. }
-
- function StrAlloc(Size: Cardinal): PChar;
-
- { StrBufSize returns the allocated size of the given buffer, not including
- the two byte header. }
-
- function StrBufSize(const Str: PChar): Cardinal;
-
- { StrNew allocates a copy of Str on the heap. If Str is NIL, StrNew returns
- NIL and doesn't allocate any heap space. Otherwise, StrNew makes a
- duplicate of Str, obtaining space with a call to the StrAlloc function,
- and returns a pointer to the duplicated string. To dispose the string,
- use StrDispose. }
-
- function StrNew(const Str: PChar): PChar;
-
- { StrDispose disposes a string that was previously allocated with StrAlloc
- or StrNew. If Str is NIL, StrDispose does nothing. }
-
- procedure StrDispose(Str: PChar);
-
- { String formatting routines }
-
- { The Format routine formats the argument list given by the Args parameter
- using the format string given by the Format parameter.
-
- Format strings contain two types of objects--plain characters and format
- specifiers. Plain characters are copied verbatim to the resulting string.
- Format specifiers fetch arguments from the argument list and apply
- formatting to them.
-
- Format specifiers have the following form:
-
- "%" [index ":"] ["-"] [width] ["." prec] type
-
- A format specifier begins with a % character. After the % come the
- following, in this order:
-
- - an optional argument index specifier, [index ":"]
- - an optional left-justification indicator, ["-"]
- - an optional width specifier, [width]
- - an optional precision specifier, ["." prec]
- - the conversion type character, type
-
- The following conversion characters are supported:
-
- d Decimal. The argument must be an integer value. The value is converted
- to a string of decimal digits. If the format string contains a precision
- specifier, it indicates that the resulting string must contain at least
- the specified number of digits; if the value has less digits, the
- resulting string is left-padded with zeros.
-
- u Unsigned decimal. Similar to 'd' but no sign is output.
-
- e Scientific. The argument must be a floating-point value. The value is
- converted to a string of the form "-d.ddd...E+ddd". The resulting
- string starts with a minus sign if the number is negative, and one digit
- always precedes the decimal point. The total number of digits in the
- resulting string (including the one before the decimal point) is given
- by the precision specifer in the format string--a default precision of
- 15 is assumed if no precision specifer is present. The "E" exponent
- character in the resulting string is always followed by a plus or minus
- sign and at least three digits.
-
- f Fixed. The argument must be a floating-point value. The value is
- converted to a string of the form "-ddd.ddd...". The resulting string
- starts with a minus sign if the number is negative. The number of digits
- after the decimal point is given by the precision specifier in the
- format string--a default of 2 decimal digits is assumed if no precision
- specifier is present.
-
- g General. The argument must be a floating-point value. The value is
- converted to the shortest possible decimal string using fixed or
- scientific format. The number of significant digits in the resulting
- string is given by the precision specifier in the format string--a
- default precision of 15 is assumed if no precision specifier is present.
- Trailing zeros are removed from the resulting string, and a decimal
- point appears only if necessary. The resulting string uses fixed point
- format if the number of digits to the left of the decimal point in the
- value is less than or equal to the specified precision, and if the
- value is greater than or equal to 0.00001. Otherwise the resulting
- string uses scientific format.
-
- n Number. The argument must be a floating-point value. The value is
- converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format
- corresponds to the "f" format, except that the resulting string
- contains thousand separators.
-
- m Money. The argument must be a floating-point value. The value is
- converted to a string that represents a currency amount. The conversion
- is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat,
- ThousandSeparator, DecimalSeparator, and CurrencyDecimals global
- variables, all of which are initialized from the Currency Format in
- the International section of the Windows Control Panel. If the format
- string contains a precision specifier, it overrides the value given
- by the CurrencyDecimals global variable.
-
- p Pointer. The argument must be a pointer value. The value is converted
- to a string of the form "XXXX:YYYY" where XXXX and YYYY are the
- segment and offset parts of the pointer expressed as four hexadecimal
- digits.
-
- s String. The argument must be a character, a string, or a PChar value.
- The string or character is inserted in place of the format specifier.
- The precision specifier, if present in the format string, specifies the
- maximum length of the resulting string. If the argument is a string
- that is longer than this maximum, the string is truncated.
-
- x Hexadecimal. The argument must be an integer value. The value is
- converted to a string of hexadecimal digits. If the format string
- contains a precision specifier, it indicates that the resulting string
- must contain at least the specified number of digits; if the value has
- less digits, the resulting string is left-padded with zeros.
-
- Conversion characters may be specified in upper case as well as in lower
- case--both produce the same results.
-
- For all floating-point formats, the actual characters used as decimal and
- thousand separators are obtained from the DecimalSeparator and
- ThousandSeparator global variables.
-
- Index, width, and precision specifiers can be specified directly using
- decimal digit string (for example "%10d"), or indirectly using an asterisk
- charcater (for example "%*.*f"). When using an asterisk, the next argument
- in the argument list (which must be an integer value) becomes the value
- that is actually used. For example "Format('%*.*f', [8, 2, 123.456])" is
- the same as "Format('%8.2f', [123.456])".
-
- A width specifier sets the minimum field width for a conversion. If the
- resulting string is shorter than the minimum field width, it is padded
- with blanks to increase the field width. The default is to right-justify
- the result by adding blanks in front of the value, but if the format
- specifier contains a left-justification indicator (a "-" character
- preceding the width specifier), the result is left-justified by adding
- blanks after the value.
-
- An index specifier sets the current argument list index to the specified
- value. The index of the first argument in the argument list is 0. Using
- index specifiers, it is possible to format the same argument multiple
- times. For example "Format('%d %d %0:d %d', [10, 20])" produces the string
- '10 20 10 20'.
-
- The Format function can be combined with other formatting functions. For
- example
-
- S := Format('Your total was %s on %s', [
- FormatFloat('$#,##0.00;;zero', Total),
- FormatDateTime('mm/dd/yy', Date)]);
-
- which uses the FormatFloat and FormatDateTime functions to customize the
- format beyond what is possible with Format. }
-
- function Format(const Format: string; const Args: array of const): string;
-
- { FmtStr formats the argument list given by Args using the format string
- given by Format into the string variable given by Result. For further
- details, see the description of the Format function. }
-
- procedure FmtStr(var Result: string; const Format: string;
- const Args: array of const);
-
- { StrFmt formats the argument list given by Args using the format string
- given by Format into the buffer given by Buffer. It is up to the caller to
- ensure that Buffer is large enough for the resulting string. The returned
- value is Buffer. For further details, see the description of the Format
- function. }
-
- function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar;
-
- { StrFmt formats the argument list given by Args using the format string
- given by Format into the buffer given by Buffer. The resulting string will
- contain no more than MaxLen characters, not including the null terminator.
- The returned value is Buffer. For further details, see the description of
- the Format function. }
-
- function StrLFmt(Buffer: PChar; MaxLen: Cardinal; Format: PChar;
- const Args: array of const): PChar;
-
- { FormatBuf formats the argument list given by Args using the format string
- given by Format and FmtLen into the buffer given by Buffer and BufLen.
- The Format parameter is a reference to a buffer containing FmtLen
- characters, and the Buffer parameter is a reference to a buffer of BufLen
- characters. The returned value is the number…
Large files files are truncated, but you can click here to view the full file