⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delphi常用函数库.txt

📁 delphi常用的函数库 再不用绞尽脑汁想一些已经存在的函数了
💻 TXT
📖 第 1 页 / 共 5 页
字号:
delphi 常用函数库1 - 人生路上  
      您的查询字词都已标明如下:txt 行数 delphi  (点击查询词,可以跳到它在文中首次出现的位置) 
      如果打开速度慢,您可以尝试打开无图片的快照; 如果您想保存该页面,可以添加到搜藏
      (百度和网页http://www.honesed.com/blog/article.asp?id=110的作者无关,不对其内容负责。百度快照谨为网络故障时之索引,不代表被搜索网站的即时页面。) 



人生路上 { 金麟岂是池中物,一遇风云始化龙. }博客首页心情随笔设计作品网络文摘影音在线软件开发企业管理资源下载留言 订阅 |  上一篇 |  下一篇  
软件开发 
delphi 常用函数库1作者:网络小虫 日期:2006-05-05
字体大小: 小 中 大  
{   大家都是程序员 没有必要重复一些无聊的事情 我的这些函数能给大家带来方便 } 
{               系统公用函数及过程              } 


{ 软件名称: 开发包基础库                         } 
{ 单元名称: 公共运行时间库单元                      } 
{ 单元版本: V1.0                             } 
{ 备  注: 该单元定义了组件包的基础类库                 } 
{ 开发平台: PWin98SE + Delphi 6.0                    } 
{ 兼容测试: PWin9X/2000/XP + Delphi 6.0                 } 
{ 本 地 化: 该单元中的字符串均符合本地化处理方式             } 
{ 更新记录: 2002.07.03 V2.0                      } 
{         整理单元,重设版本号                   } 
{       2002.03.17 V0.02                       } 
{         新增部分函数,并部分修改                 } 
{       2002.01.30 V0.01                       } 
{         创建单元(整理而来)                   } 

{    ①: 扩展的字符串操作函数                     } 
{    ②: 扩展的日期时间操作函数                    } 
{    ③: 扩展的位操作函数                       } 
{    ④: 扩展的文件及目录操作函数                   } 
{    ⑤: 扩展的对话框函数                       } 
{    ⑥: 系统功能函数                         } 
{    ⑦: 硬件功能函数                         } 
{    ⑧: 网络功能函数                         } 
{    ⑨: 汉字拼音函数及过程                      } 
{    ⑩: 数据库功能函数                        } 
{    ⑾: 进制功能函数                         } 
{    ⑿: 其它功能函数                         } 


unit Communal; 
{* |<PRE> 
|</PRE>} 

interface 

{$I CnPack.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; 
{▎ 觉得还一般 请关注 http://www.cdsunco.com/down.htm  还有更多的好东西   ▎} 
const 

 // 公共信息 
{$IFDEF GB2312} 
 SCnInformation = '提示'; 
 SCnWarning = '警告'; 
 SCnError = '错误'; 

 SCnInformation = 'Information'; 
 SCnWarning = 'Warning'; 
 SCnError = 'Error'; 


 C1=52845; //字符串加密算法的公匙 
 C2=22719; //字符串加密算法的公匙 

resourcestring 

{$IFDEF GB2312} 
 SUnknowError = '未知错误'; 
 SErrorCode = '错误代码:'; 

 SUnknowError = 'Unknow error'; 
 SErrorCode = 'Error code:'; 


type 
  EDBUpdateErr = class(Exception);//修改表结构时触发的错误句柄 

{▎ 觉得还一般 请关注 http://www.cdsunco.com/down.htm  还有更多的好东西   ▎} 

//▎============================================================▎// 
//▎================① 扩展的字符串操作函数 ===================▎// 
//▎============================================================▎// 

//从文件中返回Ado连接字串。 
function GetConnectionString(DataBaseName:string):string; 
//返回服务器的机器名称. 
function GetRemoteServerName:string; 

function InStr(const sShort: string; const sLong: string): Boolean;   
{* 判断s1是否包含在s2中} 

function IntToStrEx(Value: Integer; Len: Integer; FillChar: Char = '0'): string; 
 
{* 扩展整数转字符串函数 Example:  IntToStrEx(1,5,'0');  返回:"00001"} 

function IntToStrSp(Value: Integer; SpLen: Integer = 3; Sp: Char = ','): string; 
 
{* 带分隔符的整数-字符转换} 

function ByteToBin(Value: Byte): string; 
{* 字节转二进制串} 

function StrRight(Str: string; Len: Integer): string;  
{* 返回字符串右边的字符  Examples: StrRight('ABCEDFG',3);  返回:'DFG' } 

function StrLeft(Str: string; Len: Integer): string; 
{* 返回字符串左边的字符} 

function Spc(Len: Integer): string;  
{* 返回空格串} 

function Replace(Str,s1,s2:string;CaseSensitive:Boolean):string;  
{* 返回将指定字符s1用字符串s2替换后的字符串,可支持大小写敏感由CaseSensitive操作} 
{example: replace('We know what we want','we','I',false) = 'I Know what I want'} 


function Replicate(pcChar:Char; piCount:integer):string; 


function StrNum(ShortStr:string;LongString:string):Integer;   
{* 返回某个字符串中某个字符串中出现的次数} 

function FindStr(ShortStr:String;LongStrIng:String):Integer;   
{* 返回某个字符串中查找某个字符串的位置} 

function SubStr(psInput:String; BeginPlace,CutLeng:Integer):String;   
{* 返回从位置BeginPlace开始切取长度为CatLeng字符串} 

function LeftStr(psInput:String; CutLeng:Integer):String;   
{* 返回从左边第一为开始切取 CutLeng长度的字符串} 

function RightStr(psInput:String; CutLeng:Integer):String;    
{* 返回从右边第一为开始切取 CutLeng长度的字符串} 

function PadLStr(psInput:String; piWidth:Integer; pcPadWith:Char):String;     
{* 返回从psInput字符串左边开始用pcPadWith填充后总长度为PiWidth的字符串} 

function PadRStr(psInput:String; piWidth:Integer; pcPadWith:Char):String;    
{* 返回从psInput字符串右边开始用pcPadWith填充后总长度为PiWidth的字符串} 

function PadCStr(psInput:String; piWidth:Integer; pcPadWith:Char):String;     
{* 返回从psInput字符串两边开始用pcPadWith填充后总长度为PiWidth的字符串} 

function ChrTran(psInput:String; pcSearch:Char; pcTranWith:Char):String;     
{* 返回替换后字符串[替换单个字符] Examples: ChrTran('abCdEgdlkh','d','#'); 返回'abC#Eg#lkh'} 

function StrTran(psInput:String; psSearch:String; psTranWith:String):String;     

{* 返回替换后字符串[替换字符串] Examples: StrTran('aruyfbn','ruy','=====');; 返回'a=====fbn'} 

function Stuff(psInput:String; piBeginPlace,piCount:Integer; 
psStuffWith:String):String; 
{ *返回替换后字符串[替换字符串] Examples: Stuff('ABCDEFGHI',3,4,'12345');返回'AB12345GHI'} 

procedure SwapStr(var s1, s2: string);  
{* 交换字串} 

function LinesToStr(const Lines: string): string;  
{* 多行文本转单行(换行符转'\n')} 

function StrToLines(const Str: string): string;   
{* 单行文本转多行('\n'转换行符)} 

function Encrypt(const S: String; Key: Word): String; 
{* 字符串加密函数} 

function Decrypt(const S: String; Key: Word): String; 
{* 字符串解密函数} 

function varIIF(aTest: Boolean; TrueValue, FalseValue: Variant): Variant; 
function varToStr(const V: Variant): string; 
{* VarIIF及VartoStr为变体函数} 

function IsDigital(Value: string): boolean; 


function RandomStr(aLength : Longint) : String; 


//▎============================================================▎// 
//▎================② 扩展的日期时间操作函数 =================▎// 
//▎============================================================▎// 

function GetYear(Date: TDate): Integer;  
{* 取日期年份分量} 
function GetMonth(Date: TDate): Integer;  
{* 取日期月份分量} 
function GetDay(Date: TDate): Integer;  
{* 取日期天数分量} 
function GetHour(Time: TTime): Integer;  
{* 取时间小时分量} 
function GetMinute(Time: TTime): Integer;  
{* 取时间分钟分量} 
function GetSecond(Time: TTime): Integer;  
{* 取时间秒分量} 
function GetMSecond(Time: TTime): Integer;  
{* 取时间毫秒分量} 
function GetMonthLastDay(Cs_Year,Cs_Month:string):string; 
{ *传入年、月,得到该月份最后一天} 
function IsLeapYear( nYear: Integer ): Boolean; 

function MaxDateTime(const Values: array of TDateTime): TDateTime; 

function MinDateTime(const Values: array of TDateTime): TDateTime; 

function dateBeginOfMonth(D: TDateTime): TDateTime; 

function DateEndOfMonth(D: TDateTime): TDateTime; 

function DateEndOfYear(D: TDateTime): TDateTime; 

function DaysBetween(Date1, Date2: TDateTime): integer; 


//▎============================================================▎// 
//▎===================③ 扩展的位操作函数 ====================▎// 
//▎============================================================▎// 

type 
 TByteBit = 0..7; 
 {* Byte类型位数范围} 
 TWordBit = 0..15; 
 {* Word类型位数范围} 
 TDWordBit = 0..31; 
 {* DWord类型位数范围} 

procedure SetBit(var Value: Byte; Bit: TByteBit; IsSet: Boolean); overload; 
{* 设置二进制位} 
procedure SetBit(var Value: WORD; Bit: TWordBit; IsSet: Boolean); overload; 
{* 设置二进制位} 
procedure SetBit(var Value: DWORD; Bit: TDWordBit; IsSet: Boolean); overload; 
{* 设置二进制位} 

function GetBit(Value: Byte; Bit: TByteBit): Boolean; overload; 
{* 取二进制位} 
function GetBit(Value: WORD; Bit: TWordBit): Boolean; overload; 
{* 取二进制位} 
function GetBit(Value: DWORD; Bit: TDWordBit): Boolean; overload; 
{* 取二进制位} 

//▎============================================================▎// 
//▎=================④扩展的文件及目录操作函数=================▎// 
//▎============================================================▎// 

function MoveFile(const sName, dName: string): Boolean;  
{* 移动文件、目录,参数为源、目标名} 

procedure FileProperties(const FName: string); 
{* 打开文件属性窗口} 

function OpenDialog(var FileName: string; Title: string; Filter: string; 
 Ext: string): Boolean; 
{* 打开文件框} 

function FormatPath(APath: string; Width: Integer): string; 
{* 缩短显示不下的长路径名} 

function GetRelativePath(Source, Dest: string): string;  
{* 取两个目录的相对路径,注意串尾不能是'\'字符!} 

procedure RunFile(const FName: string; Handle: THandle = 0; 
 const Param: string = '');  
{* 运行一个文件} 

function WinExecAndWait32(FileName: string; Visibility: Integer = SW_NORMAL): 
 Integer; 
{* 运行一个文件并等待其结束} 

function AppPath: string; 
{* 应用程序路径} 

function GetWindowsDir: string; 
{* 取Windows系统目录} 

function GetWinTempDir: string;  
{* 取临时文件目录} 

function AddDirSuffix(Dir: string): string;  
{* 目录尾加'\'修正} 

function MakePath(Dir: string): string;  
{* 目录尾加'\'修正} 

function IsFileInUse(FName: string): Boolean;  
{* 判断文件是否正在使用} 

function GetFileSize(FileName: string): Integer;  
{* 取文件长度} 

function SetFileDate(FileName: string; CreationTime, LastWriteTime, 
LastAccessTime: 
 TFileTime): Boolean;   
{* 设置文件时间 Example:  FileSetDate('c:\Test\Test1.exe',753160662);  } 

function GetFileDate(FileName: string; var CreationTime, LastWriteTime, 
LastAccessTime: 
 TFileTime): Boolean;   
{* 取文件时间} 

function FileTimeToLocalSystemTime(FTime: TFileTime): TSystemTime;  
{* 文件时间转本地时间} 

function LocalSystemTimeToFileTime(STime: TSystemTime): TFileTime;  
{* 本地时间转文件时间} 

function GetFileIcon(FileName: string; var Icon: TIcon): Boolean;  
{* 取得与文件相关的图标,成功则返回True} 

function CreateBakFile(FileName, Ext: string): Boolean;  
{* 创建备份文件} 

function Deltree(Dir: string): Boolean;   
{* 删除整个目录} 

function GetDirFiles(Dir: string): Integer;   
{* 取文件夹文件数} 

type 
 TFindCallBack = procedure(const FileName: string; const Info: TSearchRec; 
  var Abort: Boolean); 
{* 查找指定目录下文件的回调函数} 

procedure FindFile(const Path: string; const FileName: string = '*.*'; 
 Proc: TFindCallBack = nil; bSub: Boolean = True; const bMsg: Boolean = True); 
{* 查找指定目录下文件} 

procedure 
FindFileList(Path,Filter:string;FileList:TStrings;ContainSubDir:Boolean); 
{ 功能说明:查找一个路径下的所有文件。 
 参数: path:路径,filter:文件扩展名过滤,FileList:文件列表, ContainSubDir:是否包含子目录} 

function Txtline(const txt: string): integer; 
{* 返回一文本文件的行数} 

function Html2Txt(htmlfilename: string): string; 
{* Html文件转化成文本文件} 

function OpenWith(const FileName: string): Integer;   
{* 文件打开方式} 

//▎============================================================▎// 
//▎====================⑤扩展的对话框函数======================▎// 
//▎============================================================▎// 

procedure InfoDlg(Mess: string; Caption: string = SCnInformation; Flags: Integer 

 = MB_OK + MB_ICONINFORMATION);  
{* 显示提示窗口} 

function InfoOk(Mess: string; Caption: string = SCnInformation): Boolean;  
{* 显示提示确认窗口} 

procedure ErrorDlg(Mess: string; Caption: string = SCnError);   
{* 显示错误窗口} 

procedure WarningDlg(Mess: string; Caption: string = SCnWarning);  
{* 显示警告窗口} 

function QueryDlg(Mess: string; Caption: string = SCnInformation): Boolean;  
{* 显示查询是否窗口} 

procedure SetWindowAnimate(Sender : TForm; IsSetAni : bool); 

//▎============================================================▎// 
//▎=====================⑥系统功能函数=========================▎// 
//▎============================================================▎// 

procedure MoveMouseIntoControl(AWinControl: TControl);  
{* 移动鼠标到控件} 

function DynamicResolution(x, y: WORD): Boolean;   
{* 动态设置分辨率} 

procedure StayOnTop(Handle: HWND; OnTop: Boolean);  
{* 窗口最上方显示} 

procedure SetHidden(Hide: Boolean);   
{* 设置程序是否出现在任务栏} 

procedure SetTaskBarVisible(Visible: Boolean);   
{* 设置任务栏是否可见} 

procedure SetDesktopVisible(Visible: Boolean);   
{* 设置桌面是否可见} 

procedure BeginWait;   
{* 显示等待光标} 

procedure EndWait;   
{* 结束等待光标} 

function CheckWindows9598NT: string;  
{* 检测是否Win95/98/NT平台} 

function GetOSInfo : String;  
{* 取得当前操作平台是 Windows 95/98 还是NT} 

function GetCurrentUserName : string; 


function GetRegistryOrg_User(UserKeyType:string):string; 


function GetSysVersion:string; 


function WinBootMode:string; 


type 
  PShutType = (UPowerOff, UShutdown, UReboot, ULogOff, USuspend, UHibernate); 
procedure WinShutDown(ShutWinType:PShutType; PForce:Boolean); 
{//Windows ShutDown等} 

//▎============================================================▎// 
//▎=====================⑦硬件功能函数=========================▎// 
//▎============================================================▎// 

function GetClientGUID:string; 
{ 功能描述:在本机上得到一个GUID.去掉两端的大括号和中间的横线 
 返回值:去掉两端的大括号和中间的横线的一个GUID 
 适用范围:windows 
} 

function SoundCardExist: Boolean;    
{* 声卡是否存在} 

function GetDiskSerial(DiskChar: Char): string; 
{* 获取磁盘序列号} 

function DiskReady(Root: string) : Boolean; 


procedure WritePortB( wPort : Word; bValue : Byte ); 
{* 写串口} 

function ReadPortB( wPort : Word ) : Byte; 


function CPUSpeed: Double; 
{* 获知当前机器CPU的速率(MHz)} 

type 
TCPUID = array[1..4] of Longint; 
function GetCPUID : TCPUID; assembler; register; 


function GetMemoryTotalPhys : Dword; 


type 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -