?? delphi常用函數(shù)庫.txt
字號(hào):
delphi 常用函數(shù)庫1 - 人生路上
您的查詢字詞都已標(biāo)明如下:txt 行數(shù) delphi (點(diǎn)擊查詢?cè)~,可以跳到它在文中首次出現(xiàn)的位置)
如果打開速度慢,您可以嘗試打開無圖片的快照; 如果您想保存該頁面,可以添加到搜藏
(百度和網(wǎng)頁http://www.honesed.com/blog/article.asp?id=110的作者無關(guān),不對(duì)其內(nèi)容負(fù)責(zé)。百度快照謹(jǐn)為網(wǎng)絡(luò)故障時(shí)之索引,不代表被搜索網(wǎng)站的即時(shí)頁面。)
人生路上 { 金麟豈是池中物,一遇風(fēng)云始化龍. }博客首頁心情隨筆設(shè)計(jì)作品網(wǎng)絡(luò)文摘影音在線軟件開發(fā)企業(yè)管理資源下載留言 訂閱 | 上一篇 | 下一篇
軟件開發(fā)
delphi 常用函數(shù)庫1作者:網(wǎng)絡(luò)小蟲 日期:2006-05-05
字體大小: 小 中 大
{ 大家都是程序員 沒有必要重復(fù)一些無聊的事情 我的這些函數(shù)能給大家?guī)矸奖?}
{ 系統(tǒng)公用函數(shù)及過程 }
{ 軟件名稱: 開發(fā)包基礎(chǔ)庫 }
{ 單元名稱: 公共運(yùn)行時(shí)間庫單元 }
{ 單元版本: V1.0 }
{ 備 注: 該單元定義了組件包的基礎(chǔ)類庫 }
{ 開發(fā)平臺(tái): PWin98SE + Delphi 6.0 }
{ 兼容測(cè)試: PWin9X/2000/XP + Delphi 6.0 }
{ 本 地 化: 該單元中的字符串均符合本地化處理方式 }
{ 更新記錄: 2002.07.03 V2.0 }
{ 整理單元,重設(shè)版本號(hào) }
{ 2002.03.17 V0.02 }
{ 新增部分函數(shù),并部分修改 }
{ 2002.01.30 V0.01 }
{ 創(chuàng)建單元(整理而來) }
{ ①: 擴(kuò)展的字符串操作函數(shù) }
{ ②: 擴(kuò)展的日期時(shí)間操作函數(shù) }
{ ③: 擴(kuò)展的位操作函數(shù) }
{ ④: 擴(kuò)展的文件及目錄操作函數(shù) }
{ ⑤: 擴(kuò)展的對(duì)話框函數(shù) }
{ ⑥: 系統(tǒng)功能函數(shù) }
{ ⑦: 硬件功能函數(shù) }
{ ⑧: 網(wǎng)絡(luò)功能函數(shù) }
{ ⑨: 漢字拼音函數(shù)及過程 }
{ ⑩: 數(shù)據(jù)庫功能函數(shù) }
{ ⑾: 進(jìn)制功能函數(shù) }
{ ⑿: 其它功能函數(shù) }
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;
{▎ 覺得還一般 請(qǐng)關(guān)注 http://www.cdsunco.com/down.htm 還有更多的好東西 ▎}
const
// 公共信息
{$IFDEF GB2312}
SCnInformation = '提示';
SCnWarning = '警告';
SCnError = '錯(cuò)誤';
SCnInformation = 'Information';
SCnWarning = 'Warning';
SCnError = 'Error';
C1=52845; //字符串加密算法的公匙
C2=22719; //字符串加密算法的公匙
resourcestring
{$IFDEF GB2312}
SUnknowError = '未知錯(cuò)誤';
SErrorCode = '錯(cuò)誤代碼:';
SUnknowError = 'Unknow error';
SErrorCode = 'Error code:';
type
EDBUpdateErr = class(Exception);//修改表結(jié)構(gòu)時(shí)觸發(fā)的錯(cuò)誤句柄
{▎ 覺得還一般 請(qǐng)關(guān)注 http://www.cdsunco.com/down.htm 還有更多的好東西 ▎}
//▎============================================================▎//
//▎================① 擴(kuò)展的字符串操作函數(shù) ===================▎//
//▎============================================================▎//
function GetConnectionString(DataBaseName:string):string;
//返回服務(wù)器的機(jī)器名稱.
function GetRemoteServerName:string;
function InStr(const sShort: string; const sLong: string): Boolean;
{* 判斷s1是否包含在s2中}
function IntToStrEx(Value: Integer; Len: Integer; FillChar: Char = '0'): string;
{* 擴(kuò)展整數(shù)轉(zhuǎn)字符串函數(shù) Example: IntToStrEx(1,5,'0'); 返回:"00001"}
function IntToStrSp(Value: Integer; SpLen: Integer = 3; Sp: Char = ','): string;
{* 帶分隔符的整數(shù)-字符轉(zhuǎn)換}
function ByteToBin(Value: Byte): string;
{* 字節(jié)轉(zhuǎn)二進(jìn)制串}
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;
{* 返回某個(gè)字符串中某個(gè)字符串中出現(xiàn)的次數(shù)}
function FindStr(ShortStr:String;LongStrIng:String):Integer;
{* 返回某個(gè)字符串中查找某個(gè)字符串的位置}
function SubStr(psInput:String; BeginPlace,CutLeng:Integer):String;
{* 返回從位置BeginPlace開始切取長(zhǎng)度為CatLeng字符串}
function LeftStr(psInput:String; CutLeng:Integer):String;
{* 返回從左邊第一為開始切取 CutLeng長(zhǎng)度的字符串}
function RightStr(psInput:String; CutLeng:Integer):String;
{* 返回從右邊第一為開始切取 CutLeng長(zhǎng)度的字符串}
function PadLStr(psInput:String; piWidth:Integer; pcPadWith:Char):String;
{* 返回從psInput字符串左邊開始用pcPadWith填充后總長(zhǎng)度為PiWidth的字符串}
function PadRStr(psInput:String; piWidth:Integer; pcPadWith:Char):String;
{* 返回從psInput字符串右邊開始用pcPadWith填充后總長(zhǎng)度為PiWidth的字符串}
function PadCStr(psInput:String; piWidth:Integer; pcPadWith:Char):String;
{* 返回從psInput字符串兩邊開始用pcPadWith填充后總長(zhǎng)度為PiWidth的字符串}
function ChrTran(psInput:String; pcSearch:Char; pcTranWith:Char):String;
{* 返回替換后字符串[替換單個(gè)字符] 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;
{* 多行文本轉(zhuǎn)單行(換行符轉(zhuǎn)'\n')}
function StrToLines(const Str: string): string;
{* 單行文本轉(zhuǎn)多行('\n'轉(zhuǎn)換行符)}
function Encrypt(const S: String; Key: Word): String;
{* 字符串加密函數(shù)}
function Decrypt(const S: String; Key: Word): String;
{* 字符串解密函數(shù)}
function varIIF(aTest: Boolean; TrueValue, FalseValue: Variant): Variant;
function varToStr(const V: Variant): string;
{* VarIIF及VartoStr為變體函數(shù)}
function IsDigital(Value: string): boolean;
function RandomStr(aLength : Longint) : String;
//▎============================================================▎//
//▎================② 擴(kuò)展的日期時(shí)間操作函數(shù) =================▎//
//▎============================================================▎//
function GetYear(Date: TDate): Integer;
{* 取日期年份分量}
function GetMonth(Date: TDate): Integer;
{* 取日期月份分量}
function GetDay(Date: TDate): Integer;
{* 取日期天數(shù)分量}
function GetHour(Time: TTime): Integer;
{* 取時(shí)間小時(shí)分量}
function GetMinute(Time: TTime): Integer;
{* 取時(shí)間分鐘分量}
function GetSecond(Time: TTime): Integer;
{* 取時(shí)間秒分量}
function GetMSecond(Time: TTime): Integer;
{* 取時(shí)間毫秒分量}
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;
//▎============================================================▎//
//▎===================③ 擴(kuò)展的位操作函數(shù) ====================▎//
//▎============================================================▎//
type
TByteBit = 0..7;
{* Byte類型位數(shù)范圍}
TWordBit = 0..15;
{* Word類型位數(shù)范圍}
TDWordBit = 0..31;
{* DWord類型位數(shù)范圍}
procedure SetBit(var Value: Byte; Bit: TByteBit; IsSet: Boolean); overload;
{* 設(shè)置二進(jìn)制位}
procedure SetBit(var Value: WORD; Bit: TWordBit; IsSet: Boolean); overload;
{* 設(shè)置二進(jìn)制位}
procedure SetBit(var Value: DWORD; Bit: TDWordBit; IsSet: Boolean); overload;
{* 設(shè)置二進(jìn)制位}
function GetBit(Value: Byte; Bit: TByteBit): Boolean; overload;
{* 取二進(jìn)制位}
function GetBit(Value: WORD; Bit: TWordBit): Boolean; overload;
{* 取二進(jìn)制位}
function GetBit(Value: DWORD; Bit: TDWordBit): Boolean; overload;
{* 取二進(jìn)制位}
//▎============================================================▎//
//▎=================④擴(kuò)展的文件及目錄操作函數(shù)=================▎//
//▎============================================================▎//
function MoveFile(const sName, dName: string): Boolean;
{* 移動(dòng)文件、目錄,參數(shù)為源、目標(biāo)名}
procedure FileProperties(const FName: string);
{* 打開文件屬性窗口}
function OpenDialog(var FileName: string; Title: string; Filter: string;
Ext: string): Boolean;
{* 打開文件框}
function FormatPath(APath: string; Width: Integer): string;
{* 縮短顯示不下的長(zhǎng)路徑名}
function GetRelativePath(Source, Dest: string): string;
{* 取兩個(gè)目錄的相對(duì)路徑,注意串尾不能是'\'字符!}
procedure RunFile(const FName: string; Handle: THandle = 0;
const Param: string = '');
{* 運(yùn)行一個(gè)文件}
function WinExecAndWait32(FileName: string; Visibility: Integer = SW_NORMAL):
Integer;
{* 運(yùn)行一個(gè)文件并等待其結(jié)束}
function AppPath: string;
{* 應(yīng)用程序路徑}
function GetWindowsDir: string;
{* 取Windows系統(tǒng)目錄}
function GetWinTempDir: string;
{* 取臨時(shí)文件目錄}
function AddDirSuffix(Dir: string): string;
{* 目錄尾加'\'修正}
function MakePath(Dir: string): string;
{* 目錄尾加'\'修正}
function IsFileInUse(FName: string): Boolean;
{* 判斷文件是否正在使用}
function GetFileSize(FileName: string): Integer;
{* 取文件長(zhǎng)度}
function SetFileDate(FileName: string; CreationTime, LastWriteTime,
LastAccessTime:
TFileTime): Boolean;
{* 設(shè)置文件時(shí)間 Example: FileSetDate('c:\Test\Test1.exe',753160662); }
function GetFileDate(FileName: string; var CreationTime, LastWriteTime,
LastAccessTime:
TFileTime): Boolean;
{* 取文件時(shí)間}
function FileTimeToLocalSystemTime(FTime: TFileTime): TSystemTime;
{* 文件時(shí)間轉(zhuǎn)本地時(shí)間}
function LocalSystemTimeToFileTime(STime: TSystemTime): TFileTime;
{* 本地時(shí)間轉(zhuǎn)文件時(shí)間}
function GetFileIcon(FileName: string; var Icon: TIcon): Boolean;
{* 取得與文件相關(guān)的圖標(biāo),成功則返回True}
function CreateBakFile(FileName, Ext: string): Boolean;
{* 創(chuàng)建備份文件}
function Deltree(Dir: string): Boolean;
{* 刪除整個(gè)目錄}
function GetDirFiles(Dir: string): Integer;
{* 取文件夾文件數(shù)}
type
TFindCallBack = procedure(const FileName: string; const Info: TSearchRec;
var Abort: Boolean);
{* 查找指定目錄下文件的回調(diào)函數(shù)}
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);
{ 功能說明:查找一個(gè)路徑下的所有文件。
參數(shù): path:路徑,filter:文件擴(kuò)展名過濾,FileList:文件列表, ContainSubDir:是否包含子目錄}
function Txtline(const txt: string): integer;
{* 返回一文本文件的行數(shù)}
function Html2Txt(htmlfilename: string): string;
{* Html文件轉(zhuǎn)化成文本文件}
function OpenWith(const FileName: string): Integer;
{* 文件打開方式}
//▎============================================================▎//
//▎====================⑤擴(kuò)展的對(duì)話框函數(shù)======================▎//
//▎============================================================▎//
= MB_OK + MB_ICONINFORMATION);
{* 顯示提示窗口}
function InfoOk(Mess: string; Caption: string = SCnInformation): Boolean;
{* 顯示提示確認(rèn)窗口}
procedure ErrorDlg(Mess: string; Caption: string = SCnError);
{* 顯示錯(cuò)誤窗口}
procedure WarningDlg(Mess: string; Caption: string = SCnWarning);
{* 顯示警告窗口}
function QueryDlg(Mess: string; Caption: string = SCnInformation): Boolean;
{* 顯示查詢是否窗口}
procedure SetWindowAnimate(Sender : TForm; IsSetAni : bool);
//▎============================================================▎//
//▎=====================⑥系統(tǒng)功能函數(shù)=========================▎//
//▎============================================================▎//
procedure MoveMouseIntoControl(AWinControl: TControl);
{* 移動(dòng)鼠標(biāo)到控件}
function DynamicResolution(x, y: WORD): Boolean;
{* 動(dòng)態(tài)設(shè)置分辨率}
procedure StayOnTop(Handle: HWND; OnTop: Boolean);
{* 窗口最上方顯示}
procedure SetHidden(Hide: Boolean);
{* 設(shè)置程序是否出現(xiàn)在任務(wù)欄}
procedure SetTaskBarVisible(Visible: Boolean);
{* 設(shè)置任務(wù)欄是否可見}
procedure SetDesktopVisible(Visible: Boolean);
{* 設(shè)置桌面是否可見}
procedure BeginWait;
{* 顯示等待光標(biāo)}
procedure EndWait;
{* 結(jié)束等待光標(biāo)}
function CheckWindows9598NT: string;
{* 檢測(cè)是否Win95/98/NT平臺(tái)}
function GetOSInfo : String;
{* 取得當(dāng)前操作平臺(tái)是 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等}
//▎============================================================▎//
//▎=====================⑦硬件功能函數(shù)=========================▎//
//▎============================================================▎//
function GetClientGUID:string;
{ 功能描述:在本機(jī)上得到一個(gè)GUID.去掉兩端的大括號(hào)和中間的橫線
返回值:去掉兩端的大括號(hào)和中間的橫線的一個(gè)GUID
適用范圍:windows
}
function SoundCardExist: Boolean;
{* 聲卡是否存在}
function GetDiskSerial(DiskChar: Char): string;
{* 獲取磁盤序列號(hào)}
function DiskReady(Root: string) : Boolean;
procedure WritePortB( wPort : Word; bValue : Byte );
{* 寫串口}
function ReadPortB( wPort : Word ) : Byte;
function CPUSpeed: Double;
{* 獲知當(dāng)前機(jī)器CPU的速率(MHz)}
type
TCPUID = array[1..4] of Longint;
function GetCPUID : TCPUID; assembler; register;
function GetMemoryTotalPhys : Dword;
type
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -