📄 magsubs1.pas
字号:
unit magsubs1;
{ Magenta Systems File Transfer Components.
Updated by Angus Robertson, Magenta Systems Ltd, England, 25th July 2005
delphi@magsys.co.uk, http://www.magsys.co.uk/delphi/
Copyright Magenta Systems Ltd
This unit contains a wide range of general purpose functions, some written by
Magenta, some contributed by others but often improved
Thanks to Enzo from iMazzo for MSIEAutoDial improvements
WARNING - currently Delphi 5, 6 and 7 only
1st May 2001, Release 4.60
26th June 2001, Release 4.61 - added GetMACAddresses
11th October 2001, Release 4.70 - added IsDestReachable and IsNetAlive
added MSIEAutoDial and MSIEDefConn
added AddThouSeps, IntToCStr, Int64ToCStr
31st October 2001, Release 4.71 - added DirectoryExists and ForceDirs
6th Dec 2001 - Release 4.72 - added more GetShellPath literals
1st January 2002, Release 4.72 - added ExcludeTrailingPathDelimiter for D4
26th May 2002 - Release 4.80 - moved MagRasOSVersion here from magrasapi
corrected MSIEDefConn to work with Windows XP
26th July 2002 - Release 4.90
5 Jan 2004 - Release 4.93 added from magsubs4 to support magcopy, magftp, maghttp
11 Jan 2004 - Release 4.93 made Delphi 5 compatible
22 Jan 2004 - added DTtoAlpha, DTTtoAlpha, DateOnlyPacked
30 Jan 2004 - added MaxLongWrd
6 Feb 2004 - PackedDTtoISODT handles dates only, added SecsToHourStr
1 Apr 2004 - added StrCtrlSafe, StrCtrlRest, UnxToDosPath, DosToUnxPath, StrFileTran
31 May 2004 - added GetSize64File, corrected files over 4 gigs not reported correctly
1 Oct 2004 - messing with FileTimeToDateTime to fix 12/00 bug
- added CheckFileOpen
11 Oct 2004 - Release 4.94 added MSIEAutoDialOpt, fixed MSIEDefConn for XP
25 Nov 2004 - added FormatLastError, IsWinXPE, IsWin2K3
13 Dec 2004 - added CRLF_
14 Jan 2004 - added Int2Kbytes, Int2Mbytes, IntToKbyte from magsubs4
28 Jan 2005 - added EmptyRecycleBin, NULLL to avoid conflict with variants
14 Feb 2005 - more error handling in IndexFiles
22 Mar 2005 - added ULINE, TrimWorkingSetMemory
18 Apr 2005 - added GetTickCountX, DiffTicks, ElapsedTicks, ElapsedSecs, GetTrgMsecs, GetTrgSecs, TestTrgTick
6 May 2005 - added TimeToNStr always numeric hh:mm:ss, and TimeToZStr hh:mm:ss:zzz
added DateToAStr/DateTimeToAStr always alpha month and numeric hh:mm:ss
25 July 2005 - TFindList moved to magclasses.pas
}
interface
uses
Sysutils, Windows, Messages, Classes, ShellAPI, nb30, Registry ;
const
MaxByte: Byte = 255;
MaxShortInt: ShortInt = 127;
MaxWord: Word = 65535;
MaxTriplet: LongInt = $FFFFFF ;
MaxLongInt: LongInt = $7FFFFFFF;
MaxInteger = $7FFFFFFF;
MaxLongWord: LongWord = $FFFFFFFF;
MaxLongWrd = $FFFFFFFF;
MaxReal: Real = 1.7e38;
MaxSingle: Single = 3.4e38;
MaxDouble: Double = 1.7e308;
MaxExtended: Extended = 1.1e4932;
MaxComp: Comp = 9.2e18;
MinByte: Byte = 0;
MinShortInt: ShortInt = -128;
MinInt: Integer = -32768;
MinWord: Word = 0;
MinLongInt = $80000000;
MinReal: Real = 2.9e-39;
MinSingle: Single = 1.5e-45;
MinDouble: Double = 5.0e-324;
MinExtended: Extended = 3.4e-4932;
const
{ several important ASCII codes }
NULL = #0;
NULLL = #0;
BACKSPACE = #8;
TAB = #9;
LF = #10;
FF = #12;
CR = #13;
EOF_ = #26;
ESC = #27;
FIELDSEP = #28;
RECSEP = #30;
BLANK = #32;
SQUOTE = #39 ;
DQUOTE = #34 ;
SPACE = BLANK;
SLASH = '\'; { used in filenames }
BSLASH = '\'; { used in filenames }
HEX_PREFIX = '$'; { prefix for hexnumbers }
COLON = ':';
FSLASH = '/';
COMMA = ',';
PERIOD = '.';
ULINE = '_';
CRLF : PChar = CR+LF;
CRLF_ = CR+LF;
UNICODESIG : PChar = #255 + #254 ;
ASCII_NULL = #0;
ASCII_BELL = #7;
ASCII_BS = #8;
ASCII_HT = #9;
ASCII_LF = #10;
ASCII_CR = #13;
ASCII_EOF = #26;
ASCII_ESC = #27;
ASCII_SP = #32;
c_Tab = ASCII_HT;
c_Space = ASCII_SP;
c_EOL = ASCII_CR + ASCII_LF;
c_DecimalPoint = '.';
{ digits as chars }
ZERO = '0'; ONE = '1'; TWO = '2'; THREE = '3'; FOUR = '4';
FIVE = '5'; SIX = '6'; SEVEN = '7'; EIGHT = '8'; NINE = '9';
{ special codes }
{ common computer sizes }
KBYTE = Sizeof(Byte) shl 10;
MBYTE = KBYTE shl 10;
GBYTE = MBYTE shl 10;
DIGITS : set of Char = [ZERO..NINE];
NumPadCh: Char = ' '; // Character to use for Left Hand Padding of Numerics
MinsPerDay = SecsPerDay / 60 ;
OneSecond: TDateTime = 1 / SecsPerDay ;
OneMinute: TDateTime = 1 / (SecsPerDay / 60) ;
OneHour: TDateTime = 1 / (SecsPerDay / (60 * 60)) ;
FileTimeBase = -109205.0; // days between years 1601 and 1900
FileTimeStep: Extended = 24.0 * 60.0 * 60.0 * 1000.0 * 1000.0 * 10.0; // 100 nsec per Day
FileTimeSecond: int64 = 10000000 ;
FileTime1980: int64 = 119600064000000000 ;
FileTime1990: int64 = 122756256000000000 ;
FileTime2000: int64 = 125911584000000000 ;
TicksPerDay: longword = 24 * 60 * 60 * 1000 ;
TicksPerHour: longword = 60 * 60 * 1000 ;
TicksPerMinute: longword = 60 * 1000 ;
TicksPerSecond: longword = 1000 ;
DateOnlyPacked = 'yyyymmdd' ;
DateMaskPacked = 'yyyymmdd"-"hhnnss' ;
DateMaskXPacked = 'yyyymmdd"-"hhnnss"-"zzz' ;
TimeMaskPacked = 'hhnnss' ;
ISODateMask = 'yyyy-mm-dd' ;
ISODateTimeMask = 'yyyy-mm-dd"T"hh:nn:ss' ;
ISOTimeMask = 'hh:nn:ss' ;
LongTimeMask = 'hh:nn:ss:zzz' ;
FullDateTimeMask = 'yyyy/mm/dd"-"hh:nn:ss' ;
DateAlphaMask = 'dd-mmm-yyyy' ;
ShortTimeMask = 'hh:nn' ;
SDateMaskPacked = 'yymmddhhnnss' ;
DateTimeAlphaMask = 'dd-mmm-yyyy hh:nn:ss' ;
// SQL paramater constants
paramY = SQUOTE + 'Y' + SQUOTE {+ SPACE} ;
paramN = SQUOTE + 'N' + SQUOTE {+ SPACE} ;
paramBlank = SQUOTE + SQUOTE ;
paramSep = ',' ;
paramNull = 'NULL' ;
type
CharSet = Set of Char;
CharSetArray = array of CharSet;
StringArray = array of string;
T2DimStrArray = array of array of string ;
TIntegerArray = array of integer ;
const
// file type extensions - should be in windows.pas, but missing
FILE_ATTRIBUTE_DEVICE = $00000040 ; // old encrypt
FILE_ATTRIBUTE_SPARSE_FILE = $00000200 ; // file is missing records
FILE_ATTRIBUTE_REPARSE_POINT = $00000400 ; // attached function??
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = $00002000 ;
FILE_ATTRIBUTE_ENCRYPTED = $00004000 ; // W2K encrypt
faNormal = FILE_ATTRIBUTE_COMPRESSED OR FILE_ATTRIBUTE_NORMAL OR
FILE_ATTRIBUTE_ENCRYPTED OR FILE_ATTRIBUTE_NOT_CONTENT_INDEXED ; // NTFS
faNormArch = faNormal OR faArchive ;
// SENS Connectivity APIs from sensapi.h - MSIE5 and later only
const
SensapiDLL = 'SENSAPI.DLL' ;
{ Literals for IsDestReachable, values for QocInfo.dwFlags. }
NETWORK_ALIVE_LAN = $00000001 ;
NETWORK_ALIVE_WAN = $00000002 ;
NETWORK_ALIVE_AOL = $00000004 ;
{ Structure for IsDestReachable, dwFlags }
type
PQocInfo = ^TQocInfo;
TQocInfo = record
dwSize: DWORD;
dwFlags: DWORD;
dwInSpeed: DWORD;
dwOutSpeed: DWORD;
end;
// performance counter and NowPC stuff
var
PerfFreqCountsPerSec: int64 ;
f_PCStartValue: int64 ;
f_TDStartValue: TDateTime ;
f_PCCountsPerDay: extended ;
PerfFreqAligned: boolean = False ; // clear if clock changes
TicksTestOffset: longword ; // 18 Apr 2005, for testing GetTickCount
// functions exported by this unit
{ Converts a fixed length PChar string into a Delphi ANSI string, leaving
any embedded or trailing nulls. }
function FixedToPasStr (fixstr: PChar; fixsize: integer): string ;
{ Similar to FixedToPasStr, but specialised to split a PChar string into
two Delphi ANSI strings at the first embedded null. }
function GetDevNamePort (fixstr: PChar; fixsize: integer;
var devport: string): string ;
{ Simple version of StrToInt that does not raise any exceptions, it returns
zero for an illegal input. }
function AscToInt (value: string): Integer;
{ Simple version of StrToInt64 that does not raise any exceptions, it returns
zero for an illegal input. }
function AscToInt64 (value: string): Int64 ;
{ Adds thousand separators to an ASCII string (no checking for digits).
The separator value comes from ThousandSeparator and is typically a
comma. }
function AddThouSeps (const S: string): string;
{ Converts a 32-bit integer numeric value into a string with thousand
separators, typically commas, calls AddThouSeps. }
function IntToCStr (const N: integer): string ;
{ Converts a 64-bit integer numeric value into a string with thousand
separators, typically commas, calls AddThouSeps. }
function Int64ToCStr (const N: int64): string ;
{ Returns the path of the windows directory. }
function GetWinDir: String;
{ Returns the path of a specific windows shell directory, using the
CSIDL_xx literals. }
function GetShellPath (location: integer): string ;
{ Returns the user name of the current thread. This is the name of the user
currently logged onto the system. }
function GetUsersName: string;
{ Returns the NetBIOS name of the local computer. This name is established
at system startup, when the system reads it from the registry.}
function GetCompName: string;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -