📄 sysutils.pas
字号:
EPropWriteOnly = class(Exception);
EAssertionFailed = class(Exception);
{$IFNDEF PC_MAPPED_EXCEPTIONS}
EAbstractError = class(Exception) end platform;
{$ENDIF}
EIntfCastError = class(Exception);
EInvalidContainer = class(Exception);
EInvalidInsert = class(Exception);
EPackageError = class(Exception);
EOSError = class(Exception)
public
ErrorCode: DWORD;
end;
{$IFDEF MSWINDOWS}
EWin32Error = class(EOSError)
end deprecated;
{$ENDIF}
ESafecallException = class(Exception);
{$IFDEF LINUX}
{
Signals
External exceptions, or signals, are, by default, converted to language
exceptions by the Delphi RTL. Under Linux, a Delphi application installs
signal handlers to trap the raw signals, and convert them. Delphi libraries
do not install handlers by default. So if you are implementing a standalone
library, such as an Apache DSO, and you want to have signals converted to
language exceptions that you can catch, you must install signal hooks
manually, using the interfaces that the Delphi RTL provides.
For most libraries, installing signal handlers is pretty
straightforward. Call HookSignal(RTL_SIGDEFAULT) at initialization time,
and UnhookSignal(RTL_SIGNALDEFAULT) at shutdown. This will install handlers
for a set of signals that the RTL normally hooks for Delphi applications.
There are some cases where the above initialization will not work properly:
The proper behaviour for setting up signal handlers is to set
a signal handler, and then later restore the signal handler to its previous
state when you clean up. If you have two libraries lib1 and lib2, and lib1
installs a signal handler, and then lib2 installs a signal handler, those
libraries have to uninstall in the proper order if they restore signal
handlers, or the signal handlers can be left in an inconsistent and
potentially fatal state. Not all libraries behave well with respect to
installing signal handlers. To hedge against this possibility, and allow
you to manage signal handlers better in the face of whatever behaviour
you may find in external libraries, we provide a set of four interfaces to
allow you to tailor the Delphi signal handler hooking/unhooking in the
event of an emergency. These are:
InquireSignal
AbandonSignalHandler
HookSignal
UnhookSignal
InquireSignal allows you to look at the state of a signal handler, so
that you can find out if someone grabbed it out from under you.
AbandonSignalHandler tells the RTL never to unhook a particular
signal handler. This can be used if you find a case where it would
be unsafe to return to the previous state of signal handling. For
example, if the previous signal handler was installed by a library
which has since been unloaded.
HookSignal/UnhookSignal setup signal handlers that map certain signals
into language exceptions.
See additional notes at InquireSignal, et al, below.
}
const
RTL_SIGINT = 0; // User interrupt (SIGINT)
RTL_SIGFPE = 1; // Floating point exception (SIGFPE)
RTL_SIGSEGV = 2; // Segmentation violation (SIGSEGV)
RTL_SIGILL = 3; // Illegal instruction (SIGILL)
RTL_SIGBUS = 4; // Bus error (SIGBUS)
RTL_SIGQUIT = 5; // User interrupt (SIGQUIT)
RTL_SIGLAST = RTL_SIGQUIT; // Used internally. Don't use this.
RTL_SIGDEFAULT = -1; // Means all of a set of signals that the we capture
// normally. This is currently all of the preceding
// signals. You cannot pass this to InquireSignal.
type
{ TSignalState is the state of a given signal handler, as returned by
InquireSignal. See InquireSignal, below.
}
TSignalState = (ssNotHooked, ssHooked, ssOverridden);
var
{
If DeferUserInterrupts is set, we do not raise either SIGINT or SIGQUIT as
an exception, instead, we set SIGINTIssued or SIGQUITIssued when the
signal arrives, and swallow the signal where the OS issued it. This gives
GUI applications the chance to defer the actual handling of the signal
until a time when it is safe to do so.
}
DeferUserInterrupts: Boolean;
SIGINTIssued: Boolean;
SIGQUITIssued: Boolean;
{$ENDIF}
{$IFDEF LINUX}
const
MAX_PATH = 4095; // From /usr/include/linux/limits.h PATH_MAX
{$ENDIF}
var
{ Empty string and null string pointer. These constants are provided for
backwards compatibility only. }
EmptyStr: string = '';
NullStr: PString = @EmptyStr;
EmptyWideStr: WideString = '';
NullWideStr: PWideString = @EmptyWideStr;
{$IFDEF MSWINDOWS}
{ 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 = '';
{ Win32 OS version tester }
function CheckWin32Version(AMajor: Integer; AMinor: Integer = 0): Boolean;
{ GetFileVersion returns the most significant 32 bits of a file's binary
version number. Typically, this includes the major and minor version placed
together in one 32-bit integer. It generally does not include the release
or build numbers. It returns Cardinal(-1) if it failed. }
function GetFileVersion(const AFileName: string): Cardinal;
{$ENDIF}
{ 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. A value of #0 indicates
no thousand separator character should be output even if the format string
specifies thousand separators.
DecimalSeparator - The character used to separate the integer part from
the fractional part of a number. The initial value is fetched from
LOCALE_SDECIMAL. DecimalSeparator must be a non-zero value.
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;
TwoDigitYearCenturyWindow: Word = 50;
ListSeparator: Char;
{ Thread safe currency and date/time formatting
The TFormatSettings record is designed to allow thread safe formatting,
equivalent to the gloabal variables described above. Each of the
formatting routines that use the gloabal variables have overloaded
equivalents, requiring an additional parameter of type TFormatSettings.
A TFormatSettings record must be populated before use. This can be done
using the GetLocaleFormatSettings function, which will populate the
record with values based on the given locale (using the Win32 API
function GetLocaleInfo). Note that some format specifiers still require
specific thread locale settings (such as period/era names).
}
type
TFormatSettings = record
CurrencyFormat: Byte;
NegCurrFormat: Byte;
ThousandSeparator: Char;
DecimalSeparator: Char;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -