home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
sibylft1.zip
/
DOC.DAT
/
DOC
/
SPCC
/
SYSUTILS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-04-07
|
70KB
|
1,741 lines
{*******************************************************}
{ }
{ Speed-Pascal 1.5 Runtime Library }
{ System Utilities Unit (Delphi compatible) }
{ }
{ (c) 1995-96 Joerg Pleumann }
{ (c) 1996 SpeedSoft }
{ }
{ Please mail all bugs and suggestions to: }
{ }
{ Internet: sa021pl @ uni-duisburg.de }
{ FidoNet: Joerg Pleumann @ 2:2448/136.6 }
{ }
{*******************************************************}
unit SysUtils;
{ Define compiler symbol GR to include German resource file.
Otherwise the default (English) resource file will be used. }
{$ifdef gr}
{$r German}
{$else gr}
{$r English}
{$endif gr}
interface
{ Define compiler symbol GUI to include functions from
OS/2 PM API. If you need a version of SysUtils that
uses only OS/2 base API functions (and therefore lacks
some features), comment this line out and recompile the
unit. Change this to produce programs that run without
the OS/2 PM being active (may also need changes in
System unit). Normally you shouldn't change this. }
{$define GUI}
{$ifdef OS2}
{$ifdef GUI}
uses
Os2Def,BseDos, BseErr, PmWin, PmShl;
{$else GUI}
uses
Os2Def,BseDos, BseErr;
{$endif GUI}
{$endif OS2}
{$ifdef WIN95}
uses
WinNT, WinBase, WinUser;
{$endif WIN95}
{ Constants for spcc notification and error messages and month / day names. }
{$I SPCC.INC}
type
{ Pointer to floating point value. }
PExtended = ^Extended;
type
//Override Exception definition from system to allow formatted create...
Exception=class(SysException)
public
constructor CreateFmt(const Msg:string;const Args:array of const);
constructor CreateRes(Ident:WORD);
constructor CreateResFmt(Ident:WORD;const Args:array of const);
constructor CreateResNLS(Ident:WORD);
constructor CreateResNLSFmt(Ident:WORD;const Args:array of const);
constructor CreateHelp(const Msg:string;AHelpContext:LONGINT);
constructor CreateFmtHelp(const Msg:string;const Args:array of const;AHelpContext:LONGINT);
constructor CreateResHelp(Ident:WORD;AHelpContext:LONGINT);
constructor CreateResFmtHelp(Ident:WORD;const Args:array of const;AHelpContext:LONGINT);
constructor CreateResNLSHelp(Ident:WORD;AHelpContext:LONGINT);
constructor CreateResNLSFmtHelp(Ident:WORD;const Args:array of const;AHelpContext:LONGINT);
end;
ExceptClass = class OF Exception;
EConvertError = class(Exception);
const
{ File open modes - A legal file open mode is a logical combination
of an open mode and a sharing mode. Please note that OS/2 normally
doesn't allow fmShareCompat, but for reasons of compatibility the
file functions automatically replace this constant by
fmShareDenyNone. }
{$ifdef OS2}
fmOpenRead = $0000;
fmOpenWrite = $0001;
fmOpenReadWrite = $0002;
fmShareCompat = $0000;
fmShareExclusive = $0010;
fmShareDenyWrite = $0020;
fmShareDenyRead = $0030;
fmShareDenyNone = $0040;
{$endif}
{$ifdef Win95}
fmOpenRead = $80000000;
fmOpenWrite = $40000000;
fmOpenReadWrite = $C0000000;
fmShareCompat = $00000003;
fmShareExclusive = $00000000;
fmShareDenyWrite = $00000001;
fmShareDenyRead = $00000002;
fmShareDenyNone = $00000003;
{$endif}
{ File attribute constants - Please note that there is no constant
faVolumeID, since OS/2 handles volume IDs in another way than DOS
does. }
faReadOnly = $0001;
faHidden = $0002;
faSysFile = $0004;
faDirectory = $0010;
faArchive = $0020;
faAnyFile = faReadOnly or faHidden or faSysFile or faDirectory or faArchive;
{ 'Must' attribute constants - OS/2-specific file attribute constants
for searching files. Use these constants in logical combination
with the normal file attributes when calling FindFirst() to restrict
the search results. }
faMustReadOnly = $0100;
faMustHidden = $0200;
faMustSysFile = $0400;
faMustDirectory = $1000;
faMustArchive = $2000;
const
{ File lock-timeout - This timeout value is used when performing file
locking / unlocking operations. Value is given in ms. }
LockTimeout: LongInt = 5000;
type
{ Support for date and time operations - Both values are stored in
one floating point value. The integer part contains the days passed
since 31-Dec-0000, assuming that the Gregorian calendar has always
been used. The fractional part contains the part of the day since
00:00:00. The time part is always equal to or greater than zero
and smaller than one. }
TDateTime = Extended;
const
SecsPerDay = 24 * 60 * 60;
MSecsPerDay = SecsPerDay * 1000;
type
{ Some type conversion records. }
WordRec = record
Lo, Hi: Byte;
end;
LongRec = record
Lo, Hi: Word;
end;
TMethod = record
Code, Data: Pointer;
end;
{ Some useful arrays. }
PByteArray = ^TByteArray;
TByteArray = array[0..MaxLongInt] of Byte;
PWordArray = ^TWordArray;
TWordArray = array[0..MaxLongInt div 2] of Word;
{ Generic procedure type. }
TProcedure = procedure;
{ Generic filename type }
TFileName = string;
{ File search record - This is the data structure internally used
by the FindFirst, FindNext, and FindClose functions. }
TSearchRec = record
{$IFDEF Win95}
InternalAttr:LongWord;
SearchRecIntern:WIN32_FIND_DATA;
{$ENDIF}
HDir: LongWord;
Attr: Byte;
Time: Longint;
Size: Longint;
Name: string;
end;
{ FloatToText codes - These codes are used to specify the basic
output format of the various functions that convert floating
point values to strings. }
TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
{ FloatToDecimal result record - This record is used to hold the return
value of the FloatToDecimal function. }
TFloatRec = record
Exponent: Integer;
Negative: Boolean;
Digits: array[0..18] of Char;
end;
const
{ Empty string and pointer to empty string - Used internally by various
string functions. }
EmptyStr: string[1] = '';
NullStr: PString = @EmptyStr;
var
{ --- Date, time, and currency defaults ---
The following global variables contain default values for formatting
date, time, and currency values. Most of them are queried from the
system at program startup. Some others are taken from the
application's resources. }
{ DateSeparator - The character used to separate year, month, and day,
when converting a TDateTime value to text. Queried from the system
at program startup. }
DateSeparator: Char;
{ ShortDateFormat - The default format string used when converting a
TDateTime value to text. This one is used whenever a short result
is desired. The value is computed at program startup. }
ShortDateFormat: string[15];
{ LongDateFormat - The default format string used when converting a
TDateTime value to text. This one is used whenever a long result
is desired. The value is computed at program startup. }
LongDateFormat: string[31];
{ ShortMonthNames - Abbreviations for month names used when converting
a TDateTime value to text. The names are taken from the program's
resources. }
ShortMonthNames: array[1..12] of string[7];
{ LongMonthNames - The full month names used when converting a
TDateTime value to text. The names are taken from the program's
resources. }
LongMonthNames: array[1..12] of string[15];
{ ShortDayNames - Abbreviations for day names used when converting
a TDateTime value to text. The names are taken from the program's
resources. }
ShortDayNames: array[1..7] of string[7];
{ LongDayNames - The full day names used when converting a TDateTime
value to text. The names are taken from the program's resources. }
LongDayNames: array[1..7] of string[15];
{ DateOrder - The order of year, month, and day assumed when trying to
extract date information from a string. Queried from the system at
program startup. }
DateOrder: Byte;
{ TimeSeparator - The character used to separate hour, minute, and
second, when converting a TDateTime value to text. Queried from the
system at program startup. }
TimeSeparator: Char;
{ TimeAMString - The string appended to time values between 00:00 and
11:59 when converting a DateTime value to text. Only used when
12-hour clock format is used. Queried from the system at program
startup. }
TimeAMString: string[7];
{ TimePMString - The string appended to time values between 12:00 and
23:59 when converting a DateTime value to text. Only used when
12-hour clock format is used. Queried from the system at program
startup. }
TimePMString: string[7];
{ ShortTimeFormat - The default format string used when converting a
TDateTime value to text. This one is used whenever a shorter result
is desired. Queried from the system at program startup. }
ShortTimeFormat: string[15];
{ LongTimeFormat - The default format string used when converting a
TDateTime value to text. This one is used whenever a longer result
is desired. Queried from the system at program startup. }
LongTimeFormat: string[31];
{ TwelveHours - Indicates whether 12-hour clock format is used when
trying to extract time information from a string. Queried from
the system at program startup. }
TwelveHours: Boolean;
{ CurrencyString - The local currency string used when converting
currency values to text. Default value is queried from the system
at program startup. }
CurrencyString: string[7];
{ CurrencyFormat - The order of currency value, currency string, and
separating space used when converting currency values to text.
Default value is queried from the system at program startup.
The following values four are possible, with the fifth one
being an additional value that is only supported by OS/2:
0 = '$1' 1 = '1$' 2 = '$ 1' 3 = '1 $'
4 = Currency string replaces decimal indicator }
CurrencyFormat: Byte;
{ NegCurrFormat - Corresponds to CurrencyFormat, but is used when
converting negative currency values to text. Queried from the
system at program startup.
The following values are possible:
0 = '($1)' 1 = '-$1' 2 = '$-1' 3 = '$1-'
4 = '(1$)' 5 = '-1$' 6 = '1-$' 7 = '1$-'
8 = '-1 $' 9 = '-$ 1' 10 = '$ 1-'
Since OS/2 doesn't support a special format for negative currency
values, a format is chosen that matches the CurrencyFormat with
a preceding '-'. The following list shows the possible values:
CurrencyFormat NegCurrFormat
0 = '$1' 1 = -$1
1 = '1$' 5 = -1$
2 = '$ 1' 9 = -$ 1
3 = '1 $' 8 = -1 $ }
NegCurrFormat: Byte;
{ ThousandSeparator - The character used to separate blocks of three
digits when converting floating point values to text. Queried from
the system at program startup. }
ThousandSeparator: Char;
{ DecimalSeparator - The character used to separate the integer part
from the fractional part when converting floating point values to
text. Queried from the system at program startup. }
DecimalSeparator: Char;
{ CurrencyDigits - The number of digits used in the fractional part
of a currency value when converting a currency value to text.
Queried from the system at program startup. }
CurrencyDecimals: Byte;
{ ListSeparator - The character to use when separating items in a list.
Currently not used by any function. }
ListSeparator: Char;
{ --- Memory management --- }
{ AllocMem - Allocates a memory block of the desired size on the heap.
In contrast to the GetMem standard procedure, AllocMem fills the
whole block with zeroes. }
function AllocMem(Size: Cardinal): Pointer;
{ ReAllocMem - Re-allocates a previously allocated memory block and
changes its size. Copies the contents of the old block into the
new one. CurSize and NewSize specify the current and the new size
of the block. If the new size is larger than the current size, the
additional bytes are zeroed. The old memory block is automatically
disposed. Note that the resulting pointer will always be different
from the old pointer, even if the size isn't changed. The function
can handle NIL pointers and zero blocks. }
function ReAllocMem(P: Pointer; CurSize, NewSize: Cardinal): Pointer;
{ --- Exit procedure handling --- }
{ AddExitProc - Adds a parameterless procedure to the list of
procedures to be called when the program is terminated. Note that
the procedure that is added last will be called first. }
procedure AddExitProc(Proc: TProcedure);
{ CallExitProcs - Calls all procedures that were installed by
AddExitProc and deletes them from the list. Note that the
procedure that was added last will be called first. }
procedure CallExitProcs;
{ --- String handling --- }
{ NewStr - Allocates a block of memory on the heap and fills it with
the given string, returns a PString to the memory block. The memory
block's size will be exactly one byte more than the string's real
length. Empty strings don't use any heap space, the function returns
NullStr in this case. Since NullStr points to EmptyStr, the function
never returns NIL, so you can always de-reference the resulting
pointer. Use DisposeStr to free the memory block. }
function NewStr(const S: String): PString;
{ DisposeStr - Disposes a block of memory on the heap that contains
a string. The block must have been allocated by a call to NewStr.
If the given pointer is NullStr (and thereby references the empty
string) or NIL, the function does absolutely nothing. }
procedure DisposeStr(P: PString);
{ AssignStr - Assigns a new value to a string pointer that has been
previously allocated by a call to NewStr, or is NIL. The old string
is disposed by DisposeStr, and the new one is allocated by NewStr. }
procedure AssignStr(var P: PString; const S: string);
{ AppendStr - Appends a string to the end of another. }
procedure AppendStr(var Dest: string; const S: string);
{ UpperCase - Converts a string to upper case by simply changing all
occurences of 'a'..'z' to the corresponding upper case characters.
If you want a conversion that also considers international special
characters, use AnsiUpperCase. }
function UpperCase(const S: string): string;
{ LowerCase - Converts a string to lower case by simply changing all
occurences of 'A'..'Z' to the corresponding lower case characters.
If you want a conversion that also considers international special
characters, use AnsiLowerCase. }
function LowerCase(const S: string): string;
{ CompareStr - Compares two strings and returns an integer value
as in the following table:
S1 < S2 Result < 0
S1 = S2 Result = 0
S1 > S2 Result > 0
CompareStr is case-sensitive, but does not take international
special characters or the currently selected codepage into account. }
function CompareStr(const S1, S2: string): Integer;
{ CompareText - Compares two strings and returns an integer value
as in the following table:
S1 < S2 Result < 0
S1 = S2 Result = 0
S1 > S2 Result > 0
CompareText is case-insensitive, and does not take international
special characters or the currently selected codepage into account. }
function CompareText(const S1, S2: string): Integer;
{ AnsiUpperCase - Converts a string to upper case. This function
also takes international special characters and the currently
selected codepage into account. If you don't want this, use
UpperCase. }
function AnsiUpperCase(const S: string): string;
{ AnsiLowerCase - Converts a string to lower case. This function
also takes international special characters and the currently
selected codepage into account. If you don't want this, use
LowerCase. Note that AnsiLowerCase is not available under OS/2. }
{$ifndef os2}
function AnsiLowerCase(const S: string): string;
{$endif}
{ AnsiCompareStr - Compares two strings and returns an integer value
as in the following table:
S1 < S2 Result < 0
S1 = S2 Result = 0
S1 > S2 Result > 0
AnsiCompareStr is case-sensitive, and takes international special
characters and the currently selected codepage into account. Note
that the function is not available under OS/2. }
{$ifndef OS2}
function AnsiCompareStr(const S1, S2: string): Integer;
{$endif}
{ AnsiCompareText - Compares two strings and returns an integer value
as in the following table:
S1 < S2 Result < 0
S1 = S2 Result = 0
S1 > S2 Result > 0
AnsiCompareText is case-insensitive, and takes international special
characters and the currently selected codepage into account. }
function AnsiCompareText(const S1, S2: string): Integer;
{ Trim - Removes leading and trailing spaces and control characters. }
function Trim(const S: string): string;
{ TrimLeft - Removes leading spaces and control characters. }
function TrimLeft(const S: string): string;
{ TrimRight - Removes trailing spaces and control characters. }
function TrimRight(const S: string): string;
{ QuotedStr - Returns the given string enclosed in quotes. Quotes already
included in the string are returned as two quote characters. }
function QuotedStr(const S: string): string;
{ IsValidIdent - Checks whether the given string contains a legal
Pascal identifier. Check your Speed-Pascal manual to see what a
legal identifier looks like. :-) }
function IsValidIdent(const Ident: string): Boolean;
{ IntToStr - Converts an integer value to a string of digits. }
function IntToStr(Value: LongInt): string;
{ IntToHex - Converts an integer value to a string of hexadecimal
digits. The minimum desired number of digits can be specified.
If the result contains less digits, it is left-padded with zeroes. }
function IntToHex(Value: LongInt; Digits: Integer): string;
{ StrToInt - Extracts an integer value from a string. If the string
doesn't contain a legal integer value, exception EConvertError
is raised. }
function StrToInt(const S: string): LongInt;
{ StrToIntDef - Extracts an integer value from a string. If the string
doesn't contain a legal integer value, the desired default value
is returned instead. }
{$ifdef GUI}
function StrToIntDef(const S: string; Default: LongInt): LongInt;
{$endif GUI}
{ LoadStr - Loads a string from the application's resources. The
string is retrieved by an integer number. If the resources don't
contain a string with the given number, LoadStr returns an empty
string. }
{$ifdef GUI}
function LoadStr(Ident: Word): string;
{$endif GUI}
{ LoadNLSStr - Loads a string from the application's current language table. The
string is retrieved by an integer number. If the resources don't
contain a string with the given number, LoadStr returns an empty
string. }
function LoadNLSStr(Ident: Word): string;
{ LoadTableStr - Loads a string from the specified string table. The
string is retrieved by an integer number. If the resources don't
contain a string with the given number, LoadStr returns an empty
string. }
function LoadTableStr(const Table:string;Ident: Word): string;
{ FmtLoadStr - Loads a string from the application's resources and
replaces some placeholders by values given in an open-array. The
string is retrieved by an integer number. If the resources don't
contain a string with the given number, FmtLoadStr returns an
empty string. }
{$ifdef GUI}
function FmtLoadStr(Ident: Word; const Args: array of const): string;
{$endif GUI}
{ FmtLoadNLSStr - Loads a string from the application's current language table and
replaces some placeholders by values given in an open-array. The
string is retrieved by an integer number. If the resources don't
contain a string with the given number, FmtLoadStr returns an
empty string. }
function FmtLoadNLSStr(Ident: Word; const Args: array of const): string;
{ FmtLoadTableStr - Loads a string from the specified string table and
replaces some placeholders by values given in an open-array. The
string is retrieved by an integer number. If the resources don't
contain a string with the given number, FmtLoadStr returns an
empty string. }
function FmtLoadTableStr(const Table:string;Ident: Word; const Args: array of const): string;
{ SysErrorMessage - Returns a system error message. }
{$ifdef OS2}
function SysErrorMessage(MsgNum: LongInt): string;
{$endif OS2}
{ --- File management --- }
{ FileOpen - Opens an existing file with a given file mode. The file
mode is a logical combination of one of the file open constants
(fmOpenXXX) and one of the sharing mode constants (fmShareXXX). If
the file is successfully opended, the resulting integer value is
positive and contains the file handle. Otherwise the result is the
negative value of the error code returned by the operating system. }
function FileOpen(const FileName: string; Mode: Word): LongInt;
{ FileCreate - Creates a new file or overwrites an existing one. No
file mode can be specified, so the file is always created with
fmOpenWrite or fmShareExclusive. If the file is successfully
created, the resulting integer value is positive and contains the
file handle. Otherwiese the result is the negative value of the
error code returned by the operating system. }
function FileCreate(const FileName: string): LongInt;
{ FileOpenOrCreate - Opens or creates a file, depending on whether
the file already exists or not. A file mode can be specified. The
file mode is a logical combination of one of the file open constants
(fmOpenXXX) and one of the sharing mode constants (fmShareXXX). If
the file is successfully opended or created, the resulting integer
value is positive and contains the file handle. Otherwise the
result is the negative value of the error code returned by the
operating system. }
function FileOpenOrCreate(const FileName: string; Mode: Word): LongInt;
{ FileCreateIfNew - Creates a file if there's not already a file with
the same name. A file mode can be specified. The file mode is a
logical combination of one of the file open constants (fmOpenXXX)
and one of the sharing mode constants (fmShareXXX). If the new file
is successfully created, the resulting integer value is positive and
contains the file handle. Otherwise the result is the negative value
of the error code returned by the operating system. Note that this
function also fails if the file already exists. }
function FileCreateIfNew(const FileName: string; Mode: Word): LongInt;
{ FileRead - Attempts to read up to Count bytes from the given file
handle and returns the number of bytes actually read. If an error
occurs, the result is -1. }
function FileRead(Handle: LongInt; var Buffer; Count: Longint): Longint;
{ FileWrite - Attempts to write up to Count bytes to the given file
handle and returns the number of bytes actually written. If an error
occurs, the result is -1. }
function FileWrite(Handle: LongInt; const Buffer; Count: LongInt): LongInt;
{ FileSeek - Changes the current position of a file handle by Count
bytes. The actual movement depends on the value of Origin, according
to the following table:
Origin Action
0 Move relative to the file's beginning
1 Move relative to the current position
2 Move relative to the file's end
The function returns the new position, or -1 if an error occured. }
function FileSeek(Handle: LongInt; Offset: LongInt; Origin: Integer): LongInt;
{ FileClose - Closes a file and frees the handle. }
procedure FileClose(Handle: LongInt);
{ FileLock - Locks a range of a file for exclusive access by the
application. Returns a Boolean value indicating success or
failure. Note that the function waits up to the time specified
in the LockTimeout global variable before it fails. }
function FileLock(Handle, Offset, Range: LongInt): Boolean;
{ FileUnLock - Unlocks a range of a file that was previously locked
for exclusive access by the application. Returns a Boolean value
indicating success or failure. }
function FileUnlock(Handle, Offset, Range: LongInt): Boolean;
{ FileAge - Returns the date and time of a file's last modification.
If the file doesn't exist, -1 is returned instead.
To use date / time formatting functions for this value, convert it
to a TDateTime by a call to FileDateToDateTime first. }
function FileAge(const FileName: string): Longint;
{ FileExists - Indicates whether a file exists or not. }
function FileExists(const FileName: string): Boolean;
{ FindFirst - Starts a search for files specified by a name pattern
and file attributes.
Any pattern that is allowed on the command line is also a legal
argument for Path.
Attr is a logical combination of file attributes (faXXX) and
file-must attributes (faMustXXX), the latter being available only
under OS/2.
The var SearchRec will contain name and attributes of the first file
that matched the given specs. In this case the function returns 0.
If an error occurs, the result is the negative value of the error
code returned by the operating system.
Use FindNext to find more files and FindClose to end the file
search. Note that you must use FindClose, or you may run out of
handles after a while. }
function FindFirst(const Path: string; Attr: Integer; var SearchRec: TSearchRec): LongInt;
{ FindNext - After a call to FindNext, the var SearchRec contains the
next file that matches the specs of a file search previously started
by FindFirst.
A return value of 0 indicates success. You may call FindNext until
an error occures (with the negative value of the operating system's
error code returned), or until no more matching files are found
(usually indicated by a return value of -18.) }
function FindNext(var SearchRec: TSearchRec): LongInt;
{ FindClose - Ends a file search previously started by FindFirst. Note
that you must use FindClose, or you may run out of handles after a
while. }
procedure FindClose(var SearchRec: TSearchRec);
{ FileGetDate - Returns the date and time of a file's last
modification. If the given file handle is invalid, -1 is returned
instead.
To use date / time formatting functions for the result, convert
it to a TDateTime by a call to FileDateToDateTime first. }
function FileGetDate(Handle: LongInt): Longint;
{ FileSetDate - Changes the date and time of a file's last
modification. If the operation fails due to an invalid handle or
an illegal Age parameter, the date and time remain unchanged.
This procedure doesn't accept TDateTime values. You have to convert
them to a LongInt by DateTimeToFileDate first. }
procedure FileSetDate(Handle: Integer; Age: Longint);
{ FileGetAttr - Returns a file's attributes. The result value is a
logical combination of file attribute constants (faXXX). If the
function fails due to a non-existing file or another error
condition, the result is the negative value of the operating
system's error code. }
function FileGetAttr(const FileName: string): LongInt;
{ FileSetAttr - Changes a file's attributes. The Attr parameter may
contain any logical combination of file attribute constants
(faXXX). A result value of 0 indicates success. If the function
fails due to a non-existing file or another error condition, the
result is the negative value of the operating system's error code. }
function FileSetAttr(const FileName: string; Attr: Integer): Integer;
{ CopyFile - Copies a file. Result is a Boolean indicating success or
failure. }
function CopyFile(const SourceName, DestName: string): Boolean;
{ DeleteFile - Deletes a file. Result is a Boolean indicating success
or failure. }
function DeleteFile(const FileName: string): Boolean;
{ RenameFile - Renames a file. Result is a Boolean indicating success
or failure. You may use RenameFile to move a file to a new location,
but only if the drive stays the same. }
function RenameFile(const OldName, NewName: string): Boolean;
{ ChangeFileExt - Changes the extension of a given filename. The
extension is the part from the rightmost dot to the end of the
filename. If the old filename doesn't contain an extension, it
is simply added. The extension must start with a dot.
Note that the function only handles a string, but does not perform
any physical changes to files. }
function ChangeFileExt(const FileName, Extension: string): string;
{ ExtractFilePath - Returns the drive and directory parts of a
filename, that is, everything from the start to the rightmost colon
or backslash in the string. If the filename doesn't contain drive or
directory information, an empty string is returned. }
function ExtractFilePath(const FileName: string): string;
{ ExtractFileName - Returns the name and extension parts of a
filename, that is, everything from rightmost colon or backslash to
the end of the string. If the filename doesn't contain a name or
extension, an empty string is returned. }
function ExtractFileName(const FileName: string): string;
{ ExtractFileExt - Returns the extension part of a filename, that is,
everything from rightmost dot to the end of the string. If the
filename doesn't contain a dot, an empty string is returned. }
function ExtractFileExt(const FileName: string): string;
{ ConcatFileName - Concatenates two filenames, assuming the first
one specifies some kind of directory information, and the second
one a filename. The result is a complete legal pathname. The
function automatically inserts a backslash, if necessary. }
function ConcatFileName(const PathName, FileName: string): string;
{ ExpandFileName - Expands a filename to an absolute filename, that
is, a filename containing a drive letter, directory information
relative to the root of the drive, and the filename. Embedded '..'
are removed. }
function ExpandFileName(FileName: string): string;
{ EditFileName - Changes a filename using a pattern possibly
containing the wildcards '*' and '?'. Everything that would
be accepted by the COPY command should be legal for Name and
Edit. }
function EditFileName(const Name, Edit: string): string;
{ FileSearch - Searches for a file Name in a list of directories
given by DirList. The directory entries must be separated by
semicolons, just like the system's PATH. The working directory
is implicitly prepended to the list of directories. The result
string is either the first occurence of the file complete with
the directory it was found in, or the empty string, if the file
could not be found. }
function FileSearch(const Name, DirList: string): string;
{ DiskFree - Returns the free space of the given disk drive. Drive 0
is the current drive, Drive 1 is 'A:', and so on. If the given drive
is invalid or cannot be read, -1 is returned, otherwise the result
contains the number of bytes free. }
function DiskFree(Drive: Byte): Longint;
{ DiskSize - Returns the disk size of the given disk drive. Drive 0
is the current drive, Drive 1 is 'A:', and so on. If the given drive
is invalid or cannot be read, -1 is returned, otherwise the result
contains the number of bytes that can be potentially used for file
storage. }
function DiskSize(Drive: Byte): Longint;
{ FileDateToDateTime - Converts a file date / time value to a
TDateTime that can be used within formatting operations. }
function FileDateToDateTime(FileDate: Longint): TDateTime;
{ FileDateToDateTime - Converts a TDateTime to a file date / time
value that can be used within file functions. }
function DateTimeToFileDate(DateTime: TDateTime): Longint;
{ --- 'C'-like string handling --- }
{ StrLen - Returns the length of Str, ignoring the terminating zero. }
function StrLen(Str: PChar): Cardinal;
{ StrEnd - Returns a pointer to the terminating zero of Str. }
function StrEnd(Str: PChar): PChar;
{ StrMove - Copies exactly Count characters from Source to Dest. It's
okay when Source and Dest overlap, StrMove can handle this. }
function StrMove(Dest, Source: PChar; Count: Cardinal): PChar;
{ StrCopy - Copies Source to Dest and returns Dest. }
function StrCopy(Dest, Source: PChar): PChar;
{ StrECopy - Copies Source to Dest and returns a pointer to the
terminating zero of the resulting string. }
function StrECopy(Dest, Source: PChar): PChar;
{ StrLCopy - Copies a maximum of MaxLen characters from Source to Dest
and returns Dest. }
function StrLCopy(Dest, Source: PChar; MaxLen: Cardinal): PChar;
{ StrPCopy - Copies a Pascal string Source to a PChar Dest and returns
Dest. }
function StrPCopy(Dest: PChar; const Source: String): PChar;
{ StrPLCopy - Copies a maximum of MaxLen characters from a Pascal
string Source to a PChar Dest. Returns Dest. }
function StrPLCopy(Dest: PChar; const Source: string; MaxLen: Cardinal): PChar;
{ StrCat - Concatenates Dest and Source, that is, appends Source to
the end of Dest, and returns Dest. }
function StrCat(Dest, Source: PChar): PChar;
{ StrLCat - Concatenates Dest and Source, that is, appends Source to
the end of Dest, but copies only so many characters that the
resulting string does not exceed MaxLen characters. Returns Dest. }
function StrLCat(Dest, Source: PChar; MaxLen: Cardinal): PChar;
{ StrComp - Compares two strings and returns an integer value
as in the following table:
Str1 < Str2 Result < 0
Str1 = Str2 Result = 0
Str1 > Str2 Result > 0
StrComp is case-sensitive, but does not take international special
characters or the currently selected codepage into account. }
function StrComp(Str1, Str2: PChar): Integer;
{ StrIComp - Compares two strings and returns an integer value
as in the following table:
Str1 < Str2 Result < 0
Str1 = Str2 Result = 0
Str1 > Str2 Result > 0
StrComp is case-insensitive, and does not take international
special characters or the currently selected codepage into account. }
function StrIComp(Str1, Str2: PChar): Integer;
{ StrLComp - Compares up to MaxLen characters of two strings and
returns an integer value as in the following table:
Str1 < Str2 Result < 0
Str1 = Str2 Result = 0
Str1 > Str2 Result > 0
StrLComp is case-sensitive, but does not take international special
characters or the currently selected codepage into account. }
function StrLComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
{ StrLIComp - Compares up to MaxLen characters of two strings and
returns an integer value as in the following table:
Str1 < Str2 Result < 0
Str1 = Str2 Result = 0
Str1 > Str2 Result > 0
StrLComp is case-insensitive, and does not take international
special characters or the currently selected codepage into account. }
function StrLIComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
{ StrScan - Searches for the first occurence of a character in a
string. Returns the pointer to the occurence, or NIL, if the
character cannot be found. }
function StrScan(Str: PChar; Chr: Char): PChar;
{ StrRScan - Searches for the last occurence of a character in a
string. Returns the pointer to the occurence, or NIL, if the
character cannot be found. }
function StrRScan(Str: PChar; Chr: Char): PChar;
{ StrScan - Searches for the first occurence of a SubStr in a given
string Str. Returns the pointer to the occurence, or NIL, if the
SubStr cannot be found. }
function StrPos(Str, SubStr: PChar): PChar;
{ StrUpper - Converts a string to upper case by simply changing all
occurences of 'a'..'z' to the corresponding upper case characters.
Returns a pointer to the string. Changes the source string, does
not create a new string. Does also not take international special
characters or the currently selected codepage into account. }
function StrUpper(Str: PChar): PChar;
{ StrLower - Converts a string to lower case by simply changing all
occurences of 'A'..'Z' to the corresponding lower case characters.
Returns a pointer to the string. Changes the source string, does
not create a new string. Does also not take international special
characters or the currently selected codepage into account. }
function StrLower(Str: PChar): PChar;
{ StrPas - Converts a PChar Str to a Pascal string. }
function StrPas(Str: PChar): String;
{ StrAlloc - Allocates a block of memory for storing PChars. The size
is specified and stored in a double word that preceeds the buffer.
Use StrDispose to free the buffer. }
function StrAlloc(Size: Cardinal): PChar;
{ StrBufSize - Returns the size of a PChar buffer that has been
previously allocated by StrAlloc. }
function StrBufSize(Str: PChar): Cardinal;
{ StrNew - Creates a copy of a given string. In contrast to StrCopy,
StrNew allocates a memory block that can hold the string, by a
call to StrAlloc. Then it copies the source string. The new
string can be disposed by a call to StrDispose. }
function StrNew(Str: PChar): PChar;
{ StrDispose - Disposes a PChar buffer that has been previously
allocated by a call to StrAlloc. }
procedure StrDispose(Str: PChar);
{ --- String formatting --- }
{ Format - Formats a string and replaces placeholders by arguments.
The format string can contain arbitrary text. This text is simply
copied into the result. Everything that starts with a '%' is
considered a placeholder. Placeholders are replaced by the
parameters given in the variant-type open-array Args. The first
placeholder is replaced by the first argument, the second one
by the second argument, and so on. You must specify at least as many
parameters as there are placeholders, otherwise an exception
EConvertError will be raised.
The way a placeholder / argument pair will be handled is controlled
by some optional specifiers. The line below shows the possibilities.
Text in " " must appear literally, 'index', 'width' and 'precision'
must be replaced by integer numbers, and 'type' must be replaced by
a character that specifies the argument type.
Parts enclosed in angular brackets are optional, the angular
brackets must not appear in the format specifier, they are only used
to show the syntax.
"%" [index ":"] ["-"] [width] ["." precision] type
The different parts of the format specifier must appear in the
given order, and they have the following meaning:
"%" Begins the format specifier
index ":" Takes the next argument from the array entry
given by Integer value index. Normally the
arguments are used one after the other. This
part of the format specifier allows to change
this behaviour.
"-" Left-Justifies the text inserted for the format
specifier. Normally the text is justified to
the right. Only applies if the string is left-
padded with spaces by the width-specifier.
width Integer value that specifies the width being
reserved for the argument. If the string
resulting from the conversion of the argument
contains less than width characters, it is
left padded with spaces to achieve this minimum
length. If "-" is used to activate left-
justification, the string is padded to the
right rather than to the left. If the string
already has a length equal to or greater than
width, no padding is needed.
"." precision Integer value that specifies the precision
used when converting the argument. The actual
consequences of precision depend on the
argument type. See descriptions below for
details.
The index, width, and precision specifiers can also contain an
asterisk ('*'). In this case, the real value is taken from the
next argument array entry, which has to be an integer value, or
EConvertError will be raised.
Following are the characters allowed to specify the argument type.
Note that 'decimal point' and 'thousand separator' mean that the
characters contained in the global variables DecimalSeparator and
ThousandSeparator will be inserted.
d Decimal format. The corresponding argument must
be an integer value, otherwise EConvertError is
raised. The argument is converted to a decimal
string. If a precision is specified, the string
is guaranteed to have at least a number of
digits equal to precision. If the string is
shorter, it is padded with zeroes.
e Scientific (exponential) format. The
corresponding argument must be a floating point
value, otherwise EConvertError is raised. The
argument is converted to a decimal string using
scientific notation. The string starts with a
minus sign, if the argument is negative. One
digit always precedes the decimal point. The
number of digits following the decimal point is
controlled by the optional precision specifier.
The total number of digits is always equal to
precision. If precision is not specified, a
default of 15 is assumed, resulting in 1 digit
before and 14 after the decimal point.
Following is the exponential 'E' with a plus or
a minus sign and up to 3 digits indicating the
exponent.
f Fixed point format. The corresponding argument
must be a floating point value, otherwise
EConvertError is raised. The argument is
converted to a string using fixed notation. It
starts with a minus sign, if the argument is
negative. All digits of the argument's integer
part appear in the result. Following is a
decimal separator and a number of digits equal
to precision. If no precision is specified, a
default of 2 decimal places is assumed.
g General number format. The argument must be a
floating point value, otherwise EConvertError
is raised. The argument is converted to a
string using either fixed or scientific format,
depending on which results in a shorter string.
The optional precision specifier controls the
number of significant digits (used for
rounding) with a default of 15. The result will
contain neither unnecessary zeroes nor an
unnecessary decimal point. If the argument
value is greater than or equal to 0.00001, and
if the number of digits to the left of the
decimal point is less than or equal to the
precision, fixed format is used. Otherwise the
result uses scientific format.
m Currency (money) format. The corresponding
argument must be a floating point value,
otherwise EConvertError is raised. The argument
is converted to a string using the following
global variables:
CurrencyString
CurrencyFormat
NegCurrFormat
CurrencyDecimals
If a precision is specified, it overrides the
default value of CurrencyDecimals.
n Number format. Equal to fixed, but the result
string will contain thousand separators.
p Pointer format. The corresponding argument must
be a pointer value, otherwise EConvertError is
raised. The value is converted to a string
containing the hexadecimal representation of
the pointer, with an additional ':' in the
middle. The resulting string has always a
length of 9 characters. Since we are dealing
with flat memory model, we have a full 32-bit
pointer with no segment part, only offset.
s String format. The corresponding argument must
be a single character, a string or a PChar value,
otherwise EConvertError is raised. The argument
is simply copied to the destination string. If
a precision is specified, it is considered the
maximum length of the argument string. Longer
strings will be truncated.
x Hexadecimal format. The corresponding argument
must be an integer value, otherwise EConvertError
is raised. The argument is converted to a
hexadecimal string. If a precision is specified,
the string is guaranteed to have at least a
number of digits equal to precision. If the
string is shorter, it is padded with zeroes. }
function Format(const Format: string; const Args: array of const): string;
{ FmtStr - Formats a string and replaces placeholders by arguments.
See Format for a detailed description of the format string and the
argument array. }
procedure FmtStr(var Result: string; const Format: string;
const Args: array of const);
{ StrFmt - Formats a string and replaces placeholders by arguments.
Note that the Buffer must be large enough to hold the complete
result, otherwise a protection fault (EGPFault) may occur. See
Format for a detailed description of the format string and the
argument array. }
function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar;
{ StrLFmt - Formats a string and replaces placeholders by arguments.
The function ensures that the size of the output string written into
Buffer won't exceed MaxLen characters. The function's result is also
a pointer to Buffer. See Format for a detailed description of the
format string and the argument array. }
function StrLFmt(Buffer: PChar; MaxLen: Cardinal; Format: PChar;
const Args: array of const): PChar;
{ FormatBuf - Formats a string and replaces placeholders by arguments.
Format and Buffer strings are given as untyped var / const
parameters. Their sizes are given in BufLen and FmtLen. The function
ensures that the size of the output string written into Buffer won't
exceed BufLen characters. The result value is the number of
characters actually written into Buffer. See Format for a detailed
description of the format string and the argument array. }
function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
FmtLen: Cardinal; const Args: array of const): Cardinal;
{ --- Floating point conversion --- }
{ FloatToStrF - Converts a floating point number to a string. The
appearance of the result string can be controlled by specifying
a basic format to apply, a precision, and a number of digits.
The precision parameter should be less than or equal to 18. The
meaning of the digits parameter depends on the format chosen.
Following is a detailed description of the possible formats:
ffCurrency Money (currency) format. The argument is converted
to a string using the following global variables:
CurrencyString
CurrencyFormat
NegCurrFormat
The Digits parameter specifies the number of digits
following the decimal point (0 to 18 being legal
values).
ffExponent Scientific (exponential) format. The argument is
converted to a decimal string using scientific
notation. The string starts with a minus sign, if
the argument is negative. One digit precedes the
decimal point. The number of digits following the
decimal point is controlled by Precision. The total
number of digits is always equal to Precision.
Following is the exponential 'E' with a plus or a
minus sign and the exponent with a minimum length
of Digits characters (0 to 4 being legal values).
ffFixed Fixed point format. The argument is converted to a
string using fixed point notation. It starts with a
minus sign, if the argument is negative. All digits
of the argument's integer part appear in the result.
Following is a comma and a number of decimal digits
equal to Digits (0 to 18 being legal values). If
the number of digits to the left of the decimal
point is greater than Precision, the output will be
in scientific format.
ffGeneral General number format. The argument is converted
to a string using either fixed or scientific
format, depending on which results in a shorter
string. The result will contain neither trailing
zeroes nor an unnecessary decimal point. If the
argument value is greater than or equal to 0.00001,
and if the number of digits to the left of the
decimal point is less than or equal to Precision,
fixed format is used. Otherwise the result is
formatted in scientific format with Digits
specifying the minimum number of digits in the
exponent (0 to 4 being legal values).
ffNumber Number format. Equal to fixed, but the result
string will contain thousand separators.
If the value is not-a-number, positive infinity, or negative
infinity, then the output string will also be NAN, INF, or -INF. }
function FloatToStrF(Value: Extended; Format: TFloatFormat;
Precision, Digits: Integer): string;
{ FloatToStr - Converts a floating point value to a string using
general number format and 15 significant digits. See FloatToStrF
for more details. }
function FloatToStr(Value: Extended): string;
{ FloatToText - Converts a floating point number to a string. The
result is written to Buffer without a zero teminator being
appended. The caller has to ensure that the buffer is large
enough to hold the result. The result can be controlled using
Format, Precision and Digits parameters. See FloatToStrF for
a detailed description of these parameters. }
function FloatToText(Buffer: PChar; Value: Extended; Format: TFloatFormat;
Precision, Digits: Integer): Integer;
{ FormatFloat - Converts a floating point value to a string using a
specified format.
The parameter Format controls the appearance of the result string.
Format can contain up to three sections, separated from each other
by semicolons. The first section holds the format string used for
positive values, the second one holds the format for negative
values, and the third one is applied to zero values. If one of
the sections is missing or empty, the first section is used
instead. If all sections are missing or empty, general number
format is used with a precision of 15. See FloatToStrF for more
details about general number format.
Each of the three sections can contain arbitrary text, which is
simply copied to the result string. Some characters have a special
meaning, they serve as placeholders for inserting data from the
value parameter.
The following list shows all placeholders and their meaning:
0 Mandatory digit. If the value has a digit at this
position, it is copied to the result. Otherwise a
0 is inserted.
# Optional digit. If the value has a digit at this
position, it is copied to the result. Otherwise
this position of the format string will be ignored.
. Decimal separator. The first occurence of '.' in the
format string determines the position at which a decimal
separator will be inserted. The decimal separator is
taken from the global variable DecimalSeparator. Further
occurences of '.' will be ignored.
, Thousand separator. Any occurence of ',' activates the
insertion of thousand separators into the result, where
necessary. The thousand separator is taken from the
global variable DecimalSeparator.
E+ E- Scientific (exponential) format. If any of the four
e+ e- strings to the left occur in the format string, the
result will be formatted using scientific notation.
The exponential E will have the same case as in the
format string. The exponent itself will always be
preceded by its sign, if E+ or e+ are used. E- and e-
contain a sign only if the exponent value is negative.
Up to four digit placeholders can be used to specify the
minimum number of digits used for the exponent.
'...' Characters enclosed in single or double quotes will
"..." simply be copied to the result (without quotes).
The floating point value is rounded with a precision equal to the
total number of digit placeholders in the format string. Optional
digit placeholders between the leftmost and rightmost mandatory
digit placeholders will be taken as mandatory digits, so it makes
no sense to specify one ore more '#' between zeroes. If the rounded
value contains more digits in the integer part than there are
placeholders left of the decimal separator, the additional digits
will be inserted before the first placeholder. }
function FormatFloat(const Format: string; Value: Extended): string;
{ FloatToTextFmt - Converts a floating point value to a string using a
specified format. The result is written to Buffer without a
terminating zero. The caller has to ensure that the buffer is large
enough to hold the result. The number of characters actually written
to Buffer is returned. See FormatFloat for a description of the
Format parameter. }
function FloatToTextFmt(Buffer: PChar; Value: Extended;
Format: PChar): Integer;
{ StrToFloat - Converts a string to a floating point value. The string
must contain a legal floating point value, with the decimal point
being the same character as in the global variable DecimalSeparator.
It must not contain thousand separators or currency symbols. Leading
and trailing spaces are allowed. If the string does not conform
these restrictions, EConvertError is raised. }
function StrToFloat(const S: string): Extended;
{ TextToFloat - Converts a zero-terminated string to a floating point
value. The string must contain a legal floating point value, with
the decimal point being the same character as in the global variable
DecimalSeparator. It must not contain thousand separators or
currency symbols. Leading and trailing spaces are allowed. If the
string does not conform these restrictions, EConvertError is raised. }
function TextToFloat(Buffer: PChar; var Value: Extended): Boolean;
{ FloatToDecimal - Converts a floating point value to a TFLoatRec
record which separates digits, sign, and exponent. The Precision
parameter specifies the number of significant digits (with 1..18
being legal values), the Decimals parameter specifies the desired
minimum number of digits in the fractional part. Rounding is
controlled by Precision as well as by Decimals. To force a number
of significant digits even with large values, specify 9999 for
Decimals.
The resulting TFloatRec will contain the following information:
Exponent - The result's exponent. An exponent value of -32768
indicates that the value is not-a-number (NAN). Positive or
negative infinity (INF / -INF) is indicated by an exponent
value of 32767.
Negative - Indicates whether the value is negative or not. Use
this to distinguish positive from negative infinity, too. Zero
is assumed to be non-negative.
Digits - Contains the significant digits with a terminating
zero (Chr(0)). Does not contain the decimal separator. Empty,
if the value is not-a-number, or positive, or negative infinity. }
procedure FloatToDecimal(var Result: TFloatRec; Value: Extended;
Precision, Decimals: Integer);
{ --- Date / time handling --- }
{ EncodeDate - Encodes the given year, month, and day into a single
TDateTime value. The result contains the number of days passed since
the 31-Dec-0000 and the given date, assuming Gregorian calendar has
always been used. If any parameter contains an illegal value,
EConvertError is raised. }
function EncodeDate(Year, Month, Day: Word): TDateTime;
{ EncodeTime - Encodes the given hour, minute, second and millisecond
into a single TDateTime value. The result contains the fractional
part of the day passed since 00:00:00. It is always a value equal to
or greater than zero and and smaller that one. If any parameter
contains an illegal value, EConvertError is raised. }
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
{ DecodeDate - Extracts year, month, and day from a given TDateTime
value. }
procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
{ DecodeTime - Extracts hour, minute, second, and millisecond from a
given TDateTime value. }
procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
{ DayOfWeek - Extracts the day of the week from a given TDateTime
value. The days are numbered from 1 to 7 in the following order:
Sun / Mon / Tue / Wed / Thu / Fri / Sat }
function DayOfWeek(Date: TDateTime): Integer;
{ Date - Queries the current system date. }
function Date: TDateTime;
{ Time - Queries the current system time. }
function Time: TDateTime;
{ Now - Queries the current system date and time. }
function Now: TDateTime;
{ DateToStr - Converts the date part of the given TDateTime value
to a string, using the format specified in the global variable
ShortDateFormat. }
function DateToStr(Date: TDateTime): string;
{ TimeToStr - Converts the time part ao the given TDateTime value
to a string, using the format specified in the global variable
LongTimeFormat. }
function TimeToStr(Time: TDateTime): string;
{ DateTimeToStr - Converts the given TDateTime value to a string
using the formats specified in the global variables ShortDateFormat
and LongTimeFormat. The time is only appended, if the TDateTime
value contains a (fractional) time part different from 00:00:00. }
function DateTimeToStr(DateTime: TDateTime): string;
{ StrToDate - Tries to exctract date information from a string.
The functions expects the string to contain two or three numbers
separated by the character given in the global variable
DateSeparator. The order in which day, month, and year are
expected is determined by the global variable DateOrder.
If only two numbers are found, they are assumed to specify
a month and day of the current year. If the year is smaller
than 100, it is assumed to be a year of the current century.
If no legal date can be extracted from the string,
EConvertError is raised. }
function StrToDate(const S: string): TDateTime;
{ StrToTime - Tries to exctract time information from a string.
The functions expects the string to contain two or three numbers
separated by the character given in the global variable
TimeSeparator, optionally followed by 'AM' or 'PM' to indicate
12-hour format. The first two numbers are taken as hour and
minute, the optional third one as second. If no indicator for
12-hour format is found, the time is assumed to be in 24-hour
format. If no legal time can be extracted from the string,
EConvertError is raised. }
function StrToTime(const S: string): TDateTime;
{ StrToDateTime - Tries to extract date and time information from a
string. The function expects the string to contain a date optionally
followed by a time. See StrToDate and StrToTime for more details
about the string's contents. If no legal date and time can be
extracted from the string, EConvertError is raised. }
function StrToDateTime(const S: string): TDateTime;
{ FormatDateTime - Converts a TDateTime value to a string using a
format specified by the parameter Format.
The format string may contain arbitrary text, which is simply
copies to the result string. Some characters or character
sequences have a special meaning, they serve as placeholders and
are replaced by values extracted from DateTime.
The following placeholders are allowed in the format string. Their
case doesn't matter. If the format string is empty, 'c' is assumed
the default format.
c Replaced by the date formatted as specified in the
global variable ShortDateFormat. If the (fractional)
time part is different from 00:00:00, the time is
appended using the format specified in the global
variable LongTimeFormat.
d Replaced by a number indicating the day of the month,
with no leading zero.
dd Replaced by a number indicating the day of the month,
with leading zero.
ddd Replaced by the day of the week's name taken from the
global array ShortDayNames, resulting in an abbreviation
of the day's name.
dddd Replaced by the day of the week's name taken from the
global array LongDayNames, resulting in the day's full
name.
ddddd Replaced by the date formatted as specified in the
global variable ShortDateFormat.
dddddd Replaced by the date formatted as specified in the
global variable LongDateFormat.
m When used immediately after an hour placeholder,
replaced by the minute. Otherwise replaced by a
number indicating the month. No leading zeroes.
mm When used immediately after an hour placeholder,
replaced by the minute. Otherwise replaced by a
number indicating the month. Leading zeroes.
mmm Replaced by the month's name taken from the global array
ShortMonthNames, resulting in an abbreviation of the
month's name.
mmmm Replaced by the month's name taken from the global array
LongMonthNames, resulting in the month's full name.
yy Replaced by two digits indicating the year. Leading
zeroes.
yyyy Replaced by four digits indicating the year. Leading
zeroes.
h Replaced by the hour without leading zero.
hh Replaced by the hour with leading zero.
n Replaced by the minute without leading zero.
nn Replaced by the minute with leading zero.
s Replaced by the second without leading zero.
ss Replaced by the second with leading zero.
t Replaced by the time formatted as specified in the
global variable ShortTimeFormat.
tt Replaced by the time formatted as specified in the
global variable LongTimeFormat.
am/pm Indicates that 12-hour format should be used for the
preceding hour placeholder. Replaced by 'am' or 'pm',
depending on the time, with the same case as specified.
a/p Indicates that 12-hour format should be used for the
preceding hour placeholder. Replaced by 'a' or 'p',
depending on the time, with the same case as specified.
ampm Indicates that 12-hour format should be used for the
preceding hour placeholder. Replaced by a string taken
from the global variables TimeAMString or TimePMString,
depending on the time.
/ Replaced by the date separator as specified in the global
variable DateSeparator.
: Replaced by the time separator as specified in the global
variable TimeSeparator.
'...' Characters enclosed in single or double quotes will
"..." simply be copied to the result (without quotes). }
function FormatDateTime(const Format: string; DateTime: TDateTime): string;
{ DateTimeToString - Converts a TDateTime value to a string using a
format specified by the Format parameter . See FormatDateTime for
a detailed description of the format string. }
procedure DateTimeToString(var Result: string; const Format: string;
DateTime: TDateTime);
{ --- System profile support --- }
{$ifdef GUI}
{ GetProfileStr - Reads a string from the operating system's user
profile. If Section or Entry don't exist, a Default value is
returned instead. }
function GetProfileStr(const Section, Entry: cstring; const Default: string): string;
{ GetProfileChar - Reads a character from the operating system's user
profile. If Section or Entry don't exist, a Default value is
returned instead. }
function GetProfileChar(const Section, Entry: cstring; Default: Char): Char;
{ GetProfileInt - Reads an integer from the operating system's user
profile. If Section or Entry don't exist, a Default value is
returned instead. }
function GetProfileInt(const Section, Entry: cstring; Default: Integer): Integer;
{ GetFormatSettings - Queries a lot of default values used for
formatting functions from the operation system. Called automatically
in the SysUtils startup code, so an application that uses SysUtils
can always access these values immediately after program startup. }
{$endif GUI}
procedure GetFormatSettings;
{ ConvertError - Raises EConvertError with the given error message. }
procedure ConvertError(const Msg: String);
{ --- Some routines that belong into SYSTEM.PAS --- }
{ SetLength - Changes the length of a string. Please use this
procedure instead of writing S[0] := NewLength to maintain
compatibility with the forthcoming long strings that won't contain
a length-byte any more. }
{ procedure SetLength(var S: string; NewLength: Byte); }
{ StringOfChars - Returns a string that consists of
Count occurences of the given character Ch. }
function StringOfChars(Ch: Char; Count: Integer): string;
{ SetCurrentLanguageTable - sets the language table name to the specified language.
The name must start with "SIBYL_NLS_". A table with the name must exist. If the table
cannot be found or some other error occurs this function returns false, otherise true.
By convention the table must include all Sibyl default language identifiers
(see /LANGUAGE directory for examples).}
function SetCurrentLanguageTable(const Table:string):Boolean;
{ GetCurrentLanguageTable - gets the current language table name. }
function GetCurrentLanguageTable:string;
{ GetCurrentLanguage - returns the currently set language. The language string is
retrieved from the current language table with the "SLanguage" index. This function
returns an empty string on error. }
function GetCurrentLanguage:string;
implementation