DelphiFUNCTION经典.docx
- 文档编号:25703280
- 上传时间:2023-06-11
- 格式:DOCX
- 页数:116
- 大小:47.06KB
DelphiFUNCTION经典.docx
《DelphiFUNCTION经典.docx》由会员分享,可在线阅读,更多相关《DelphiFUNCTION经典.docx(116页珍藏版)》请在冰豆网上搜索。
DelphiFUNCTION经典
{▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎}
{▎软件名称:
开发包基础库▎}
{▎单元名称:
公共运行时间库单元▎}
{▎单元版本:
V1.0▎}
{▎备注:
该单元定义了组件包的基础类库▎}
{▎开发平台:
PWin98SE+Delphi6.0▎}
{▎兼容测试:
PWin9X/2000/XP+Delphi6.0▎}
{▎本地化:
该单元中的字符串均符合本地化处理方式▎}
{▎更新记录:
2002.07.03V2.0▎}
{▎整理单元,重设版本号▎}
{▎2002.03.17V0.02▎}
{▎新增部分函数,并部分修改▎}
{▎2002.01.30V0.01▎}
{▎创建单元(整理而来)▎}
{▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎}
{▎①:
扩展的字符串操作函数▎}
{▎②:
扩展的日期时间操作函数▎}
{▎③:
扩展的位操作函数▎}
{▎④:
扩展的文件及目录操作函数▎}
{▎⑤:
扩展的对话框函数▎}
{▎⑥:
系统功能函数▎}
{▎⑦:
硬件功能函数▎}
{▎⑧:
网络功能函数▎}
{▎⑨:
汉字拼音函数及过程▎}
{▎⑩:
数据库功能函数▎}
{▎⑾:
进制功能函数▎}
{▎⑿:
其它功能函数▎}
{▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎▎}
unitCommunal;
{*|
}|
interface
{$ICnPack.inc}
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,
FileCtrl,ShellAPI,CommDlg,MMSystem,WinSock,IniFiles,DBTables,BDE,
StdCtrls,ComObj,ADODB,Imm,DbCtrls,Db,Registry;
const
//公共信息
{$IFDEFGB2312}
SCnInformation='提示';
SCnWarning='警告';
SCnError='错误';
{$ELSE}
SCnInformation='Information';
SCnWarning='Warning';
SCnError='Error';
{$ENDIF}
C1=52845;//字符串加密算法的公匙
C2=22719;//字符串加密算法的公匙
resourcestring
{$IFDEFGB2312}
SUnknowError='未知错误';
SErrorCode='错误代码:
';
{$ELSE}
SUnknowError='Unknowerror';
SErrorCode='Errorcode:
';
{$ENDIF}
type
EDBUpdateErr=class(Exception);//修改表结构时触发的错误句柄
//▎============================================================▎//
//▎================①扩展的字符串操作函数===================▎//
//▎============================================================▎//
//从文件中返回Ado连接字串。
functionGetConnectionString(DataBaseName:
string):
string;
//返回服务器的机器名称.
functionGetRemoteServerName:
string;
functionInStr(constsShort:
string;constsLong:
string):
Boolean;{测试通过}
{*判断s1是否包含在s2中}
functionIntToStrEx(Value:
Integer;Len:
Integer;FillChar:
Char='0'):
string;{测试通过}
{*扩展整数转字符串函数Example:
IntToStrEx(1,5,'0');返回:
"00001"}
functionIntToStrSp(Value:
Integer;SpLen:
Integer=3;Sp:
Char=','):
string;{测试通过}
{*带分隔符的整数-字符转换}
functionByteToBin(Value:
Byte):
string;{测试通过}
{*字节转二进制串}
functionStrRight(Str:
string;Len:
Integer):
string;{测试通过}
{*返回字符串右边的字符Examples:
StrRight('ABCEDFG',3);返回:
'DFG'}
functionStrLeft(Str:
string;Len:
Integer):
string;{测试通过}
{*返回字符串左边的字符}
functionSpc(Len:
Integer):
string;{测试通过}
{*返回空格串}
functionReplace(Str,s1,s2:
string;CaseSensitive:
Boolean):
string;{测试通过}
{*返回将指定字符s1用字符串s2替换后的字符串,可支持大小写敏感由CaseSensitive操作}
{example:
replace('Weknowwhatwewant','we','I',false)='IKnowwhatIwant'}
functionReplicate(pcChar:
Char;piCount:
integer):
string;
{在一个字符串中查找某个字符串的位置}
functionStrNum(ShortStr:
string;LongString:
string):
Integer;{测试通过}
{*返回某个字符串中某个字符串中出现的次数}
functionFindStr(ShortStr:
String;LongStrIng:
String):
Integer;{测试通过}
{*返回某个字符串中查找某个字符串的位置}
functionSubStr(psInput:
String;BeginPlace,CutLeng:
Integer):
String;{测试通过}
{*返回从位置BeginPlace开始切取长度为CatLeng字符串}
functionLeftStr(psInput:
String;CutLeng:
Integer):
String;{测试通过}
{*返回从左边第一为开始切取CutLeng长度的字符串}
functionRightStr(psInput:
String;CutLeng:
Integer):
String;{测试通过}
{*返回从右边第一为开始切取CutLeng长度的字符串}
functionPadLStr(psInput:
String;piWidth:
Integer;pcPadWith:
Char):
String;{测试通过}
{*返回从psInput字符串左边开始用pcPadWith填充后总长度为PiWidth的字符串}
functionPadRStr(psInput:
String;piWidth:
Integer;pcPadWith:
Char):
String;{测试通过}
{*返回从psInput字符串右边开始用pcPadWith填充后总长度为PiWidth的字符串}
functionPadCStr(psInput:
String;piWidth:
Integer;pcPadWith:
Char):
String;{测试通过}
{*返回从psInput字符串两边开始用pcPadWith填充后总长度为PiWidth的字符串}
functionChrTran(psInput:
String;pcSearch:
Char;pcTranWith:
Char):
String;{测试通过}
{*返回替换后字符串[替换单个字符]Examples:
ChrTran('abCdEgdlkh','d','#');返回'abC#Eg#lkh'}
functionStrTran(psInput:
String;psSearch:
String;psTranWith:
String):
String;{测试通过}
{*返回替换后字符串[替换字符串]Examples:
StrTran('aruyfbn','ruy','=====');;返回'a=====fbn'}
functionStuff(psInput:
String;piBeginPlace,piCount:
Integer;psStuffWith:
String):
String;
{*返回替换后字符串[替换字符串]Examples:
Stuff('ABCDEFGHI',3,4,'12345');返回'AB12345GHI'}
procedureSwapStr(vars1,s2:
string);{测试通过}
{*交换字串}
functionLinesToStr(constLines:
string):
string;{测试通过}
{*多行文本转单行(换行符转'\n')}
functionStrToLines(constStr:
string):
string;{测试通过}
{*单行文本转多行('\n'转换行符)}
functionEncrypt(constS:
String;Key:
Word):
String;
{*字符串加密函数}
functionDecrypt(constS:
String;Key:
Word):
String;
{*字符串解密函数}
functionvarIIF(aTest:
Boolean;TrueValue,FalseValue:
Variant):
Variant;
functionvarToStr(constV:
Variant):
string;
{*VarIIF及VartoStr为变体函数}
functionIsDigital(Value:
string):
boolean;
{功能说明:
判断string是否全是数字}
functionRandomStr(aLength:
Longint):
String;
{随机字符串函数}
//▎============================================================▎//
//▎================②扩展的日期时间操作函数=================▎//
//▎============================================================▎//
functionGetYear(Date:
TDate):
Integer;{测试通过}
{*取日期年份分量}
functionGetMonth(Date:
TDate):
Integer;{测试通过}
{*取日期月份分量}
functionGetDay(Date:
TDate):
Integer;{测试通过}
{*取日期天数分量}
functionGetHour(Time:
TTime):
Integer;{测试通过}
{*取时间小时分量}
functionGetMinute(Time:
TTime):
Integer;{测试通过}
{*取时间分钟分量}
functionGetSecond(Time:
TTime):
Integer;{测试通过}
{*取时间秒分量}
functionGetMSecond(Time:
TTime):
Integer;{测试通过}
{*取时间毫秒分量}
functionGetMonthLastDay(Cs_Year,Cs_Month:
string):
string;
{*传入年、月,得到该月份最后一天}
functionIsLeapYear(nYear:
Integer):
Boolean;
{*/判断某年是否为闰年}
functionMaxDateTime(constValues:
arrayofTDateTime):
TDateTime;
{//两个日期取较大的日期}
functionMinDateTime(constValues:
arrayofTDateTime):
TDateTime;
{//两个日期取较小的日期}
functiondateBeginOfMonth(D:
TDateTime):
TDateTime;
{//得到本月的第一天}
functionDateEndOfMonth(D:
TDateTime):
TDateTime;
{//得到本月的最后一天}
functionDateEndOfYear(D:
TDateTime):
TDateTime;
{//得到本年的最后一天}
functionDaysBetween(Date1,Date2:
TDateTime):
integer;
{//得到两个日期相隔的天数}
//▎============================================================▎//
//▎===================③扩展的位操作函数====================▎//
//▎============================================================▎//
type
TByteBit=0..7;
{*Byte类型位数范围}
TWordBit=0..15;
{*Word类型位数范围}
TDWordBit=0..31;
{*DWord类型位数范围}
procedureSetBit(varValue:
Byte;Bit:
TByteBit;IsSet:
Boolean);overload;
{*设置二进制位}
procedureSetBit(varValue:
WORD;Bit:
TWordBit;IsSet:
Boolean);overload;
{*设置二进制位}
procedureSetBit(varValue:
DWORD;Bit:
TDWordBit;IsSet:
Boolean);overload;
{*设置二进制位}
functionGetBit(Value:
Byte;Bit:
TByteBit):
Boolean;overload;
{*取二进制位}
functionGetBit(Value:
WORD;Bit:
TWordBit):
Boolean;overload;
{*取二进制位}
functionGetBit(Value:
DWORD;Bit:
TDWordBit):
Boolean;overload;
{*取二进制位}
//▎============================================================▎//
//▎=================④扩展的文件及目录操作函数=================▎//
//▎============================================================▎//
functionMoveFile(constsName,dName:
string):
Boolean;{测试通过}
{*移动文件、目录,参数为源、目标名}
procedureFileProperties(constFName:
string);{测试通过}
{*打开文件属性窗口}
functionOpenDialog(varFileName:
string;Title:
string;Filter:
string;
Ext:
string):
Boolean;
{*打开文件框}
functionFormatPath(APath:
string;Width:
Integer):
string;{测试通过}
{*缩短显示不下的长路径名}
functionGetRelativePath(Source,Dest:
string):
string;{测试通过}
{*取两个目录的相对路径,注意串尾不能是'\'字符!
}
procedureRunFile(constFName:
string;Handle:
THandle=0;
constParam:
string='');{测试通过}
{*运行一个文件}
functionWinExecAndWait32(FileName:
string;Visibility:
Integer=SW_NORMAL):
Integer;{测试通过}
{*运行一个文件并等待其结束}
functionAppPath:
string;{测试通过}
{*应用程序路径}
functionGetWindowsDir:
string;{测试通过}
{*取Windows系统目录}
functionGetWinTempDir:
string;{测试通过}
{*取临时文件目录}
functionAddDirSuffix(Dir:
string):
string;{测试通过}
{*目录尾加'\'修正}
functionMakePath(Dir:
string):
string;{测试通过}
{*目录尾加'\'修正}
functionIsFileInUse(FName:
string):
Boolean;{测试通过}
{*判断文件是否正在使用}
functionGetFileSize(FileName:
string):
Integer;{测试通过}
{*取文件长度}
functionSetFileDate(FileName:
string;CreationTime,LastWriteTime,LastAccessTime:
TFileTime):
Boolean;{测试通过}
{*设置文件时间Example:
FileSetDate('c:
\Test\Test1.exe',753160662);}
functionGetFileDate(FileName:
string;varCreationTime,LastWriteTime,LastAccessTime:
TFileTime):
Boolean;{测试通过}
{*取文件时间}
functionFileTimeToLocalSystemTime(FTime:
TFileTime):
TSystemTime;{测试通过}
{*文件时间转本地时间}
functionLocalSystemTimeToFileTime(STime:
TSystemTime):
TFileTime;{测试通过}
{*本地时间转文件时间}
functionGetFileIcon(FileName:
string;varIcon:
TIcon):
Boolean;{测试通过}
{*取得与文件相关的图标,成功则返回True}
functionCreateBakFile(FileName,Ext:
string):
Boolean;{测试通过}
{*创建备份文件}
functionDeltree(Dir:
string):
Boolean;{测试通过}
{*删除整个目录}
functionGetDirFiles(Dir:
string):
Integer;{测试通过}
{*取文件夹文件数}
type
TFindCallBack=procedure(constFileName:
string;constInfo:
TSearchRec;
varAbort:
Boolean);
{*查找指定目录下文件的回调函数}
procedureFindFile(constPath:
string;constFileName:
string='*.*';
Proc:
TFindCallBack=nil;bSub:
Boolean=True;constbMsg:
Boolean=True);
{*查找指定目录下文件}
procedureFindFileList(Path,Filter:
string;FileList:
TStrings;ContainSubDir:
Boolean);
{功能说明:
查找一个路径下的所有文件。
参数:
path:
路径,filter:
文件扩展名过滤,FileList:
文件列表,ContainSubDir:
是否包含子目录}
functionTxtline(consttxt:
string):
integer;
{*返回一文本文件的行数}
functionHtml2Txt(htmlfilename:
string):
string;
{*Html文件转化成文本文件}
functionOpenWith(constFileName:
string):
Integer;{测试通过}
{*文件打开方式}
//▎============================================================▎//
//▎====================⑤扩展的对话框函数======================▎//
//▎============================================================▎//
procedureInfoDlg(Mess:
string;Caption:
string=SCnInformation;Flags:
Integer
=MB_OK+MB_ICONINFORMATION);{测试通过}
{*显示提示窗口}
functionInfoOk(Mess:
string;Caption:
string=SCnInformation):
Boolean;{测试通过}
{*显示提示确认窗口}
procedureErrorDlg(Mess:
string;Caption:
string=SCnError);{测试通过
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- DelphiFUNCTION 经典
![提示](https://static.bdocx.com/images/bang_tan.gif)