📄 magsubs1.pas
字号:
{ Returns Delphi TDateTime converted from a UNIX time stamp, being the
number of seconds since 1st January 1970. }
function TStamptoDT (stamp: DWORD): TDateTime ;
{ Gets program version information from the string resources keys in an
EXE or DLL file.
AppName is the EXE or DLL file name, KeyName is the literal describing the
key for which information should be returned, includes 'FileDescription',
'FileVersion', 'ProductVersion' (see Delphi Project Options, Version Info
for more keys). }
function GetFileVerInfo (const AppName, KeyName: string): string ;
{ Get one or more ethernet card MAC addresses for a specified PC using
NetBIOS commands. Pcname is blank for the current PC, or specifies the
computer name from which to obtain the MAC addresses. MacAddresses
is a TStringList that is returned with ASCII representations of the
MAC address in hex format, ie 00-30-84-27-C2-1E. Result is number of
MAC addresses returned, or -1 for an error. }
function GetMACAddresses (Pcname: string; MacAddresses: TStrings): integer ;
{ Load the Synchronization Manager SENSAPI.DLL, returns false if it's
not available. The DLL is only available with MSIE 5 and later, or
Win98, W2K, XP. }
function LoadSensapi: Boolean;
{ Determines whether the local system is connected to a network and the
type of network connection, for example, LAN, WAN, or both. Flags returns
NETWORK_ALIVE_LAN or NETWORK_ALIVE_WAN (RAS). Result is true if there
is a network connection. Note a LAN connection does not necessarily
mean that internet access is also available.
Requires MSIE 5 or later, or Win98, W2K, XP. }
function IsNetAlive (var Flags: DWORD): boolean ;
{ Determines if the specified destination can be reached and provides
Quality of Connection (QOC) information for the destination. Dest can
be an IP address, a UNC name, or an URL, which will be pinged or blank,
if QOC only is required. Returns true if the destination was specified
and can be reached, QocInfo.Flags returns NETWORK_ALIVE_LAN or
NETWORK_ALIVE_WAN (RAS), dwInSpeed/dwOutSpeed are the network adaptor
speed, 1000000 or 100000000 for LANs, 34000, 56000, 64000, etc for RAS.
Note you can not check the speed of a specific device as such, only a route.
Warning - this API does not appear to be totally reliable, ping often fails
or gets blocked.
Requires MSIE 5 or later, or Win98, W2K, XP. }
function IsDestReachable (Dest: string; var QocInfo: TQocInfo): boolean ;
// MSIE internet options
const
CVKey = 'Software\Microsoft\Windows\CurrentVersion' ;
{ Allows the MSIE Internet Option 'Dial-Up Settings' to be checked or
set, Value is true for 'always dial my default connection', false for
'never dial a connection' ('dial whenever a connection is not available
is not supported by this function). If Update is false, Value returns
the current setting, if Update is true the Value should be set with the
new setting. Result is false if there's a registy error.
Effectively this is an auto dial option, when set true any application
attempting to access a remote internet server will cause RAS to dial
the default connection (see MSIEDefConn). }
function MSIEAutoDial (var Value: boolean; const Update: boolean): boolean ;
{ Allows the MSIE Internet Option 'Dial-Up Settings' to be checked or set:
0=Never Dial A Connection
1=Dial Whenever A Network Connection Is Not Present
2=Always Dial My Default Connection
If Update is false, Value returns the current setting, if Update is true
the Value should be set with the new setting. Result is false if there's
a registy error. Effectively this is an auto dial option, causing any
applicationattempting to access a remote internet server will cause RAS to
dial the default connection (see MSIEDefConn). }
function MSIEAutoDialOpt (var Value: integer; const Update: boolean): boolean;
{ Allows the MSIE Internet Option 'Dial-Up Settings' default or current
connection entry to be specified. ConnName is the name is the default
connection entry. If Update is false, Value returns the name of the
current default entry, if Update is true the Value should be set with
the new default connection. Result is false if there's a registy error.
This default connection entry is that used by auto dial,
see MSIEAutoDial. }
function MSIEDefConn (var ConnName: string; const Update: boolean): boolean ;
function DirectoryExists(const Name: string): Boolean;
function ForceDirs(Dir: string): Boolean;
// OS version stuff
function IsWin95: boolean ;
function IsWinNT: boolean ;
function IsWin2K: boolean ;
function IsWinXP: boolean ;
function IsWinXPE: boolean ;
function IsWin2K3: boolean ;
function GetOSVersion: string ;
procedure GetOSInfo ;
// validation routines
function IsDigit(Ch : Char) : Boolean;
function IsDigitsDec (info: string; decimal: boolean) : boolean ;
function IsDigits (info: string) : boolean ;
procedure ConvHexStr (instr: string; var outstr: string) ;
procedure ByteSwaps(DataPtr : Pointer;NoBytes : integer);
function ConIntHex (value: cardinal): string ; // 32-bit to 8 byte hex
function StripQuotes (filename: string): string ;
function StripNewLines (const S: string): string;
// directory and file listing
function IndexFiles (searchfile: string; mask: integer;
var FileList: TStringList; var totsize: cardinal): integer ;
function DeleteOldFiles (fname: string): integer ;
function GetEnvirVar (name: string): string ;
function StripChars (AString, AChars: string): string ;
function UpAndLower(const S: string): string;
function StripChar (const AString: string; const AChar: Char): string ;
function StripSpaces (const AString: string): string ;
function StripCommas (const AString: string): string ;
function StripNulls (const AString: string): string ;
function StripAllCntls (const AString: string): string;
procedure StringTranCh (var S: string; FrCh, ToCh: Char) ;
procedure StringCtrlSafe (var S: string) ;
procedure StringCtrlRest (var S: string) ;
procedure StringFileTran (var S: string) ;
function StringRemCntls (var S: string): boolean ;
procedure DosToUnixPath (var S: string) ;
procedure UnixToDosPath (var S: string) ;
function StrCtrlSafe (const S: string): string ;
function StrCtrlRest (const S: string): string ;
function UnxToDosPath (const S: string): string ;
function DosToUnxPath (const S: string): string ;
function StrFileTran (const S: string): string ;
{ Copy }
{ Variantions on Delphi's Copy. Just like Delphi's Copy, illegal values for }
{ Start (<1,>len), Stop (<start,>len) and Count (<0,>end) are tolerated. }
Function CopyRange (const S : String; const Start, Stop : Integer) : String;
Function CopyFrom (const S : String; const Start : Integer) : String;
Function CopyLeft (const S : String; const Count : Integer) : String;
Function CopyRight (const S : String; const Count : Integer = 1) : String;
{ Match }
{ True if M matches S [Pos] (or S [Pos..Pos+Count-1]) }
{ Returns False if Pos or Count is invalid }
Function Match (const M : CharSet; const S : String; const Pos : Integer = 1;
const Count : Integer = 1) : Boolean; overload;
Function Match (const M : CharSetArray; const S : String; const Pos : Integer = 1)
: Boolean; overload;
Function Match (const M, S : String; const Pos : Integer = 1) : Boolean; overload; // Blazing
{ PosNext }
{ Returns first Match of Find in S after LastPos. }
{ To find the first match, set LastPos to 0. }
{ Returns 0 if not found or illegal value for LastPos (<0,>length(s)) }
Function PosNext (const Find : CharSet; const S : String;
const LastPos : Integer = 0) : Integer; overload;
Function PosNext (const Find : CharSetArray; const S : String;
const LastPos : Integer = 0) : Integer; overload;
Function PosNext (const Find : String; const S : String;
const LastPos : Integer = 0) : Integer; overload;
Function PosPrev (const Find : String; const S : String;
const LastPos : Integer = 0) : Integer;
{ PosN }
{ Finds the Nth occurance of Find in S from the left or the right. }
Function PosN (const Find, S : String; const N : Integer = 1;
const FromRight : Boolean = False) : Integer;
{ Split/Join }
{ Splits S into pieces seperated by Delimiter. If Delimiter='' or S='' then }
{ returns an empty list. If Token not found in S returns list with one }
{ item, S. }
Function StrArraySplit (const S : String; const Delimiter : String = c_Space) : StringArray;
Function StrArrayJoin (const S : StringArray; const Delimiter : String = c_Space) : String;
procedure StrArrayInsert (var S: StringArray; index: integer; T: string) ;
procedure StrArrayDelete (var S: StringArray; index: integer) ;
procedure StrArrayToList (S: StringArray; var T: TStringList) ;
procedure StrArrayFromList (T: TStringList; var S: StringArray) ;
function StrArrayPosOf (L: string; S: StringArray): integer ;
// file time stamp stuff
function FileTimeToInt64 (const FileTime: TFileTime): Int64 ;
function Int64ToFileTime (const FileTime: Int64): TFileTime ;
function FileTimeToDateTime(const FileTime: TFileTime): TDateTime;
function DateTimeToFileTime(DateTime: TDateTime): TFileTime;
function FileTimeToSecs2K (const FileTime: TFileTime): integer ;
function CheckFileOpen(const FName: String): integer;
function GetSizeFile (filename: string): LongInt;
function GetSize64File (filename: string): Int64 ;
function GetFUAgeSizeFile (filename: string ; var FileTime: TFileTime ;
var FSize: Int64): boolean ;
function GetUAgeSizeFile (filename: string ; var FileDT: TDateTime;
var FSize: Int64): boolean ;
function GetFAgeSizeFile (filename: string ; var FileTime: TFileTime ;
var FSize: Int64): boolean ;
function GetAgeSizeFile (filename: string ; var FileDT: TDateTime;
var FSize: Int64): boolean ;
function TrimSpRight(const S: string): string;
function ExtractNameOnly (FileName: string): string;
function GetExceptMess (ExceptObject: TObject): string;
{ Converts a String into a LongInt }
function Str2LInt (const S: String): LongInt;
{ Converts a String into a Word }
function Str2Word (const S: String): Word;
{ Converts a String into a Byte }
function Str2Byte (const S: String): Byte;
{ Converts a String into a ShortInt }
function Str2SInt (const S: String): ShortInt;
{ Converts a String into an Integer }
function Str2Int (const S: String): Integer;
{ Converts a LongInt into a String of length N with
zeros Padding to the Left }
function Int2StrZ (const L: LongInt; const Len: Byte): String;
{ Converts a LongInt into a String of length N with
NumPadCh Padding to the Left }
function LInt2Str (const L: LongInt; const Len: Byte): String;
{ Converts a LongInt into a String of length N with
NumPadCh Padding to the Left }
function Byte2Str (const L: LongInt; const Len: Byte): String;
{ Converts a LongInt into a String of length N with
NumPadCh Padding to the Left }
function LInt2ZStr (const L: LongInt; const Len: Byte): String;
{ Converts a LongInt into a String of length N with
NumPadCh Padding to the Left, with blanks returned
if Value is 0 }
function LInt2ZBStr (const L: LongInt; const Len: Byte): String;
{ Convert a LongInt into a Comma'ed String of length Len,
with NumPadCh Padding to the Left }
function LInt2CStr (const L : LongInt; const Len : Byte): string;
{ Convert a LongInt into an exact String, No Padding }
function LInt2EStr (const L: LongInt): String;
{ Convert a LongInt into an exact String, No Padding,
with null returned if Value is 0 }
function LInt2ZBEStr (const L: LongInt): String;
{ Convert a LongInt into a Comma'ed String without Padding }
function LInt2CEStr (const L : LongInt): string;
{ Convert an Int64 to a comma'ed string, no padding }
function Int642CEStr (const L : Int64): string;
{ Returns a string composed of N occurrences of Ch. }
function FillStr (const Ch : Char; const N : Integer): string;
{ Returns a string composed of N blank spaces (i.e. #32) }
function BlankStr (const N : Integer): string;
{ Returns a string composed of N occurrences of '-'. }
function DashStr (const N : Integer): String;
{ Returns a string composed of N occurrences of '='. }
function DDashStr (const N : Integer): string;
{ Returns a string composed of N occurrences of '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -