?
This document uses PHP Chinese website manual Release
<<Delphi6函數(shù)大全3-SysUtils.pas>> 首部 function FindNext(var F: TSearchRec): Integer; $[SysUtils.pas 功能 返回繼續(xù)文件搜索 說(shuō)明 搜索成功則返回0 參考 function Windows.FindNextFile 例子 <參見(jiàn)FindFirst> ━━━━━━━━━━━━━━━━━━━━━ 首部 procedure FindClose(var F: TSearchRec); $[SysUtils.pas 功能 結(jié)束當(dāng)前文件搜索 說(shuō)明 不關(guān)閉查詢會(huì)占用系統(tǒng)資源 參考 function Windows.FindClose 例子 <參見(jiàn)FindFirst> ━━━━━━━━━━━━━━━━━━━━━ 首部 function FileGetDate(Handle: Integer): Integer; $[SysUtils.pas 功能 返回文件的修改時(shí)間 說(shuō)明 讀取失敗則返回-1 參考 function Windows.GetFileTime 例子 ///////Begin FileGetDate procedure TForm1.Button1Click(Sender: TObject); var I: Integer; begin I := FileOpen(Edit1.Text, fmOpenRead); if I < 0 then Exit; SpinEdit1.Value := FileGetDate(I); Edit2.Text := DateTimeToStr(FileDateToDateTime(SpinEdit1.Value)); FileClose(I); end; ///////End FileGetDate ━━━━━━━━━━━━━━━━━━━━━ 首部 function FileSetDate(const FileName: string; Age: Integer): Integer; overload; $[SysUtils.pas 首部 function FileSetDate(Handle: Integer; Age: Integer): Integer; overload; platform; $[SysUtils.pas 功能 返回設(shè)置文件的修改時(shí)間 說(shuō)明 修改成功則返回0 參考 function Windows.SetFileTime 例子 SpinEdit1.Value := FileSetDate(Edit1.Text, DateTimeToFileDate(StrToDateTime(Edit2.Text))); ━━━━━━━━━━━━━━━━━━━━━ 首部 function FileGetAttr(const FileName: string): Integer; platform; $[SysUtils.pas 功能 返回文件的屬性 說(shuō)明 讀取失敗則返回$FFFFFFFF 參考 function Windows.GetFileAttributes 例子 SpinEdit1.Value := FileGetAttr(Edit1.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function FileSetAttr(const FileName: string; Attr: Integer): Integer; platform; $[SysUtils.pas 功能 返回設(shè)置文件的屬性 說(shuō)明 設(shè)置成功則返回0 參考 function Windows.SetFileAttributes 例子 SpinEdit1.Value := FileSetAttr(Edit1.Text, SpinEdit2.Value); ━━━━━━━━━━━━━━━━━━━━━ 首部 function FileIsReadOnly(const FileName: string): Boolean; $[SysUtils.pas 功能 返回文件是否只讀 說(shuō)明 文件不存在看作只讀 參考 function Windows.GetFileAttributes 例子 CheckBox1.Checked := FileIsReadOnly(Edit1.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function FileSetReadOnly(const FileName: string; ReadOnly: Boolean): Boolean; $[SysUtils.pas 功能 返回設(shè)置文件是否只讀是否成功 說(shuō)明 文件不存在則返回False 參考 function Windows.GetFileAttributes;function Windows.SetFileAttributes 例子 CheckBox1.Checked := FileSetReadOnly(Edit1.Text, CheckBox2.Checked); ━━━━━━━━━━━━━━━━━━━━━ 首部 function DeleteFile(const FileName: string): Boolean; $[SysUtils.pas 功能 返回刪除文件是否成功 說(shuō)明 文件不存在則返回False 參考 function Windows.DeleteFile 例子 CheckBox1.Checked := DeleteFile(Edit1.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function RenameFile(const OldName, NewName: string): Boolean; $[SysUtils.pas 功能 返回重命名文件是否成功 說(shuō)明 文件不存在則返回False 參考 function Windows.MoveFile 例子 CheckBox1.Checked := RenameFile(Edit1.Text, Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ChangeFileExt(const FileName, Extension: string): string; $[SysUtils.pas 功能 返回改變擴(kuò)展名后的文件名 說(shuō)明 [注意]擴(kuò)展名Extension前要加點(diǎn);ChangeFileExt('a.jpg', 'bmp')='abmp' 參考 function SysUtils.LastDelimiter;function System.Copy 例子 Edit1.Text := ChangeFileExt(Edit2.Text, Edit3.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExtractFilePath(const FileName: string): string; $[SysUtils.pas 功能 返回文件名所在的路徑 說(shuō)明 ExtractFilePath('C:\')='C:\';ExtractFilePath('\\Server\Tool\Calc.exe')='\\Server\Tool\' 參考 function SysUtils.LastDelimiter;function System.Copy 例子 Edit1.Text := ExtractFilePath(Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExtractFileDir(const FileName: string): string; $[SysUtils.pas 功能 返回文件名所在的目錄 說(shuō)明 ExtractFileDir('C:\')='C:\';ExtractFileDir('\\Server\Tool\Calc.exe')='\\Server\Tool' 參考 function SysUtils.LastDelimiter;function System.Copy 例子 Edit1.Text := ExtractFileDir(Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExtractFileDrive(const FileName: string): string; $[SysUtils.pas 功能 返回文件名所在驅(qū)動(dòng)器 說(shuō)明 ExtractFileDrive('C:\')='C:';ExtractFileDrive('\\Server\Tool\Calc.exe')='\\Server\Tool' 參考 function System.Copy 例子 Edit1.Text := ExtractFileDrive(Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExtractFileName(const FileName: string): string; $[SysUtils.pas 功能 返回絕對(duì)文件名 說(shuō)明 ExtractFileName('C:\')='';ExtractFileName('\\Server\Tool\Calc.exe')='Calc.exe' 參考 function SysUtils.LastDelimiter;function System.Copy 例子 Edit1.Text := ExtractFileName(Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExtractFileExt(const FileName: string): string; $[SysUtils.pas 功能 返回文件名的擴(kuò)展名 說(shuō)明 ExtractFileExt('C:\')='';ExtractFileExt('\\Server\Tool\Calc.exe')='.exe' 參考 function SysUtils.LastDelimiter;function System.Copy 例子 Edit1.Text := ExtractFileExt(Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExpandFileName(const FileName: string): string; $[SysUtils.pas 功能 返回文件名的完整表示 說(shuō)明 ExpandFileName('hello.pas')='C:\Program Files\Borland\Delphi6\Projects\hello.pas' 參考 function Windows.GetFullPathName 例子 Edit1.Text := ExpandFileName(Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExpandFileNameCase(const FileName: string; out MatchFound: TFilenameCaseMatch): string; $[SysUtils.pas 功能 分情況返回文件名的完整表示 說(shuō)明 type TFilenameCaseMatch = (mkNone, mkExactMatch, mkSingleMatch, mkAmbiguous); 參考 function Windows.GetFullPathName;function SysUtils.SameFileName;function SysUtils.FindFirst 例子 ///////Begin ExpandFileNameCase procedure TForm1.Button1Click(Sender: TObject); var vFilenameCaseMatch: TFilenameCaseMatch; begin Edit1.Text := ExpandFileNameCase(Edit2.Text, vFilenameCaseMatch); SpinEdit1.Value := Ord(vFilenameCaseMatch); end; ///////End ExpandFileNameCase ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExpandUNCFileName(const FileName: string): string; $[SysUtils.pas 功能 返回LINUX文件名的完整表示 說(shuō)明 ExpandUNCFileName('C:/')='C:\' 參考 function SysUtils.ExpandFileName 例子 Edit1.Text := ExpandUNCFileName(Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExtractRelativePath(const BaseName, DestName: string): string; $[SysUtils.pas 功能 返回參數(shù)的相對(duì)路徑 說(shuō)明 ExtractRelativePath('C:\Windows\', 'C:\Windows\System')='System' 參考 function SysUtils.SameFilename;function SysUtils.ExtractFileDrive 例子 Edit1.Text := ExtractRelativePath(Edit2.Text, Edit3.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function ExtractShortPathName(const FileName: string): string; $[SysUtils.pas 功能 返回參數(shù)的DOS路徑 說(shuō)明 ExtractShortPathName('C:\Program Files\Borland')='C:\PROGRA~1\BORLAND' 參考 function Windows.GetShortPathName 例子 Edit1.Text := ExtractShortPathName(Edit2.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function FileSearch(const Name, DirList: string): string; $[SysUtils.pas 功能 返回目錄列表中DirList搜索的第一個(gè)結(jié)果 說(shuō)明 FileSearch('Calc.exe', 'd:\winxp\system32;c:\windows')='d:\winxp\system32\calc.exe' 參考 function SysUtils.FileExists;function SysUtils.AnsiLastChar 例子 Edit1.Text := FileSearch(Edit2.Text, Edit3.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function DiskFree(Drive: Byte): Int64; $[SysUtils.pas 功能 返回驅(qū)動(dòng)器可用空間 說(shuō)明 參數(shù)Drive為0表示當(dāng)前路徑,為1表示=A驅(qū),為2表示=B驅(qū)...;獲取失敗則返回-1 參考 function Windows.GetDiskFreeSpaceExA 例子 SpinEdit1.Value := DiskFree(SpinEdit2.Value); ━━━━━━━━━━━━━━━━━━━━━ 首部 function DiskSize(Drive: Byte): Int64; $[SysUtils.pas 功能 返回驅(qū)動(dòng)器全部空間 說(shuō)明 參數(shù)Drive為0表示當(dāng)前路徑,為1表示=A驅(qū),為2表示=B驅(qū)...;獲取失敗則返回-1 參考 function Windows.GetDiskFreeSpaceExA 例子 SpinEdit1.Value := DiskSize(SpinEdit2.Value); ━━━━━━━━━━━━━━━━━━━━━ 首部 function FileDateToDateTime(FileDate: Integer): TDateTime; $[SysUtils.pas 功能 返回將文件日期時(shí)間類(lèi)型轉(zhuǎn)換日期時(shí)間類(lèi)型 說(shuō)明 FileDate非法是將觸發(fā)異常 參考 function SysUtils.EncodeDate;function SysUtils.EncodeTime 例子 <參見(jiàn)FileAge> ━━━━━━━━━━━━━━━━━━━━━ 首部 function DateTimeToFileDate(DateTime: TDateTime): Integer; $[SysUtils.pas 功能 返回將日期時(shí)間類(lèi)型轉(zhuǎn)換文件日期時(shí)間類(lèi)型 說(shuō)明 年份在1980到2107之外則返回0 參考 function SysUtils.DecodeDate;function SysUtils.DecodeTime 例子 <參見(jiàn)FileSetDate> ━━━━━━━━━━━━━━━━━━━━━ 首部 function GetCurrentDir: string; $[SysUtils.pas 功能 返回當(dāng)前操作目錄 說(shuō)明 [注意]調(diào)用文件對(duì)話框會(huì)改變當(dāng)前操作目錄 參考 function System.GetDir 例子 Edit1.Text := GetCurrentDir; ━━━━━━━━━━━━━━━━━━━━━ 首部 function SetCurrentDir(const Dir: string): Boolean; $[SysUtils.pas 功能 返回設(shè)置當(dāng)前操作目錄是否成功 說(shuō)明 [注意]調(diào)用文件對(duì)話框會(huì)改變當(dāng)前操作目錄 參考 function Windows.SetCurrentDirectory 例子 CheckBox1.Checked := SetCurrentDir(Edit1.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function CreateDir(const Dir: string): Boolean; $[SysUtils.pas 功能 返回創(chuàng)建目錄是否成功 說(shuō)明 不支持多級(jí)目錄;已經(jīng)存在則返回False 參考 function Windows.CreateDirectory 例子 CheckBox1.Checked := CreateDir(Edit1.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function RemoveDir(const Dir: string): Boolean; $[SysUtils.pas 功能 返回刪除目錄是否成功 說(shuō)明 必須是空目錄 參考 function Windows.RemoveDirectory 例子 CheckBox1.Checked := RemoveDir(Edit1.Text); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrLen(const Str: PChar): Cardinal; $[SysUtils.pas 功能 返回指針字符串的長(zhǎng)度 說(shuō)明 當(dāng)指針字符串Str為nil時(shí)將觸發(fā)異常 參考 <NULL> 例子 SpinEdit2.Value := StrLen(PChar(Edit1.Text)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrEnd(const Str: PChar): PChar; $[SysUtils.pas 功能 返回指針字符串的結(jié)尾 說(shuō)明 當(dāng)指針字符串Str為nil時(shí)將觸發(fā)異常 參考 <NULL> 例子 Edit2.Text := StrEnd(PChar(Edit1.Text)) - SpinEdit1.Value; ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrMove(Dest: PChar; const Source: PChar; Count: Cardinal): PChar; $[SysUtils.pas 功能 返回將指針字符串Source指定內(nèi)存數(shù)量Count復(fù)制覆蓋到指針字符串Dest中 說(shuō)明 Dest沒(méi)有分配資源將觸發(fā)異常s 參考 function System.Move 例子 ///////Begin StrMove procedure TForm1.Button1Click(Sender: TObject); var vBuffer: PChar; begin vBuffer := '0123456789'; StrMove(vBuffer, PChar(Edit1.Text), SpinEdit1.Value); Edit2.Text := vBuffer; end; ///////End StrMove ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrCopy(Dest: PChar; const Source: PChar): PChar; $[SysUtils.pas 功能 返回將指針字符串Source復(fù)制到指針字符串Dest中 說(shuō)明 Dest應(yīng)已經(jīng)分配足夠的空間非則將觸發(fā)異常 參考 <NULL> 例子 ///////Begin StrCopy procedure TForm1.Button1Click(Sender: TObject); var vBuffer: PChar; begin GetMem(vBuffer, Length(Edit1.Text) + 1); StrCopy(vBuffer, PChar(Edit1.Text)); Edit2.Text := vBuffer; FreeMem(vBuffer); end; ///////End StrCopy ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrECopy(Dest:PChar; const Source: PChar): PChar; $[SysUtils.pas 功能 返回將指針字符串Source復(fù)制到指針字符串Dest中的結(jié)尾 說(shuō)明 可以連接指針字符串 參考 <NULL> 例子 ///////Begin StrECopy procedure TForm1.Button1Click(Sender: TObject); var vBuffer: array[0..255] of Char; begin StrECopy(StrECopy(vBuffer, PChar(Edit1.Text)), PChar(Edit2.Text)); Edit3.Text := vBuffer; end; ///////End StrECopy ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrLCopy(Dest: PChar; const Source: PChar; MaxLen: Cardinal): PChar; $[SysUtils.pas 功能 返回將指針字符串Source指定長(zhǎng)度MaxLen復(fù)制到指針字符串Dest中 說(shuō)明 Dest應(yīng)已經(jīng)分配足夠的空間非則將觸發(fā)異常 參考 <NULL> 例子 ///////Begin StrLCopy procedure TForm1.Button1Click(Sender: TObject); var vBuffer: array[0..255] of Char; begin StrLCopy(vBuffer, PChar(Edit1.Text), SpinEdit1.Value); Edit2.Text := vBuffer; end; ///////End StrLCopy ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrPCopy(Dest: PChar; const Source: string): PChar; $[SysUtils.pas 功能 返回將指針字符串Source復(fù)制到指針字符串Dest中 說(shuō)明 StrLCopy(Dest, PChar(Source), Length(Source)) 參考 function SysUtils.StrLCopy 例子 ///////Begin StrPCopy procedure TForm1.Button1Click(Sender: TObject); var vBuffer: array[0..255] of Char; begin StrPCopy(vBuffer, PChar(Edit1.Text)); Edit2.Text := vBuffer; end; ///////End StrPCopy ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrPLCopy(Dest: PChar; const Source: string; MaxLen: Cardinal): PChar; $[SysUtils.pas 功能 返回將字符串Source指定長(zhǎng)度MaxLen復(fù)制到指針字符串Dest中 說(shuō)明 StrLCopy(Dest, PChar(Source), MaxLen) 參考 function SysUtils.StrLCopy 例子 ///////Begin StrPLCopy procedure TForm1.Button1Click(Sender: TObject); var vBuffer: array[0..255] of Char; begin StrPLCopy(vBuffer, Edit1.Text, SpinEdit1.Value); Edit2.Text := vBuffer; end; ///////End StrPLCopy ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrCat(Dest: PChar; const Source: PChar): PChar; $[SysUtils.pas 功能 返回連接指針字符串Dest和指針字符串Source 說(shuō)明 StrCopy(StrEnd(Dest), Source) 參考 function SysUntils.StrCopy 例子 ///////Begin StrCat procedure TForm1.Button1Click(Sender: TObject); var vBuffer: array[0..255] of Char; begin StrPCopy(vBuffer, Edit1.Text); StrCat(vBuffer, PChar(Edit2.Text)); Edit3.Text := vBuffer; end; ///////End StrCat ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrLCat(Dest: PChar; const Source: PChar; MaxLen: Cardinal): PChar; $[SysUtils.pas 功能 返回連接指針字符串Dest和指針字符串Source 說(shuō)明 [注意]MaxLen指定連接后的最大長(zhǎng)度不是指針字符串Source的長(zhǎng)度 參考 <NULL> 例子 ///////Begin StrLCat procedure TForm1.Button1Click(Sender: TObject); var vBuffer: array[0..255] of Char; begin StrPCopy(vBuffer, Edit1.Text); StrLCat(vBuffer, PChar(Edit2.Text), SpinEdit1.Value); Edit3.Text := vBuffer; end; ///////End StrLCat ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrComp(const Str1, Str2: PChar): Integer; $[SysUtils.pas 功能 返回比較兩個(gè)指針字符串 說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě);[注意]返回第一個(gè)出現(xiàn)不同字符的差異 參考 <NULL> 例子 SpinEdit1.Value := StrComp(PChar(Edit1.Text), PChar(Edit2.Text)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrIComp(const Str1, Str2: PChar): Integer; $[SysUtils.pas 功能 返回比較兩個(gè)指針字符串 說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;不區(qū)分大小寫(xiě);[注意]返回第一個(gè)出現(xiàn)不同字符的差異 參考 <NULL> 例子 SpinEdit1.Value := StrIComp(PChar(Edit1.Text), PChar(Edit2.Text)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrLComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas 功能 返回比較兩個(gè)指針字符串指定長(zhǎng)度 說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;區(qū)分大小寫(xiě);Length(長(zhǎng)度);[注意]返回第一個(gè)出現(xiàn)不同字符的差異 參考 <NULL> 例子 SpinEdit1.Value := StrLComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value) ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrLIComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas 功能 返回比較兩個(gè)指針字符串指定長(zhǎng)度 說(shuō)明 當(dāng)S1>S2返回值>0;當(dāng)S1<S2返回值<0;當(dāng)S1=S2返回值=0;不區(qū)分大小寫(xiě);[注意]返回第一個(gè)出現(xiàn)不同字符的差異 參考 <NULL> 例子 SpinEdit1.Value := StrLIComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value) ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrScan(const Str: PChar; Chr: Char): PChar; $[SysUtils.pas 功能 返回在指針字符串Str搜索字符Chr第一個(gè)出現(xiàn)的地址 說(shuō)明 沒(méi)有找到則返回空指針 參考 <NULL> 例子 Edit2.Text := StrScan(PChar(Edit1.Text), '*'); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrRScan(const Str: PChar; Chr: Char): PChar; $[SysUtils.pas 功能 返回在指針字符串Str搜索字符Chr最后一個(gè)出現(xiàn)的地址 說(shuō)明 沒(méi)有找到則返回空指針 參考 <NULL> 例子 Edit2.Text := StrRScan(PChar(Edit1.Text), '*'); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrPos(const Str1, Str2: PChar): PChar; $[SysUtils.pas 功能 返回指針字符串Str2在Str1中第一個(gè)出現(xiàn)的地址 說(shuō)明 沒(méi)有找到則返回空指針;StrPos('12345', '3') = '345' 參考 <NULL> 例子 Edit3.Text := StrPos(PChar(Edit1.Text), PChar(Edit2.Text)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrUpper(Str: PChar): PChar; $[SysUtils.pas 功能 返回指針字符串Str大寫(xiě) 說(shuō)明 非小寫(xiě)字符不處理 參考 <NULL> 例子 Edit1.Text := StrUpper(PChar(Edit2.Text)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrLower(Str: PChar): PChar; $[SysUtils.pas 功能 返回指針字符串Str小寫(xiě) 說(shuō)明 非大寫(xiě)字符不處理 參考 <NULL> 例子 Edit1.Text := StrLower(PChar(Edit2.Text)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrPas(const Str: PChar): string; $[SysUtils.pas 功能 返回指針字符串Str轉(zhuǎn)換成字符串 說(shuō)明 也可以直接賦值 參考 <NULL> 例子 Edit1.Text := StrPas(PChar(Edit2.Text)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrAlloc(Size: Cardinal): PChar; $[SysUtils.pas 功能 返回分配指定空間的內(nèi)存資源給指針字符串 說(shuō)明 空間的大小也將保存;用StrDispose才能全部釋放 參考 function System.GetMem 例子 ///////Begin StrAlloc procedure TForm1.Button1Click(Sender: TObject); var P: PChar; begin P := StrAlloc(SpinEdit1.Value); ShowMessage(IntToStr(StrLen(P))); Dec(P, SizeOf(Cardinal)); ShowMessage(IntToStr(Cardinal(Pointer(P)^))); Inc(P, SizeOf(Cardinal)); StrDispose(P); end; ///////End StrAlloc ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrBufSize(const Str: PChar): Cardinal; $[SysUtils.pas 功能 返回通過(guò)函數(shù)StrAlloc分配的緩沖區(qū)大小 說(shuō)明 出現(xiàn)異常情況則返回不可預(yù)知的結(jié)果 參考 function System.SizeOf 例子 SpinEdit1.Value := StrBufSize(StrAlloc(SpinEdit2.Value)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrNew(const Str: PChar): PChar; $[SysUtils.pas 功能 返回復(fù)制一個(gè)新的指針字符串 說(shuō)明 如果Str為nil則返回nil 參考 function SysUtils.StrLen;function SysUtils.StrMove;function SysUtils.StrAlloc 例子 ///////Begin StrNew,StrDispose procedure TForm1.Button1Click(Sender: TObject); var P: PChar; begin P := StrNew(PChar(Edit1.Text)); ShowMessage(P); StrDispose(P); end; ///////End StrNew,StrDispose ━━━━━━━━━━━━━━━━━━━━━ 首部 procedure StrDispose(Str: PChar); $[SysUtils.pas 功能 釋放指針字符串Str內(nèi)存資源 說(shuō)明 如果Str為nil則不作任何處理;并且釋放空間大小信息 參考 function System.Dec;function System.SizeOf;function System.FreeMem 例子 <參見(jiàn)StrNew> ━━━━━━━━━━━━━━━━━━━━━ 首部 function Format(const Format: string; const Args: array of const): string; $[SysUtils.pas 功能 返回按指定方式格式化一個(gè)數(shù)組常量的字符形式 說(shuō)明 這個(gè)函數(shù)是我在Delphi中用得最多的函數(shù),現(xiàn)在就列舉幾個(gè)例子給你個(gè)直觀的理解 "%" [索引 ":"] ["-"] [寬度] ["." 摘要] 類(lèi)型 Format('x=%d', [12]); //'x=12' //最普通 Format('x=%3d', [12]); //'x= 12' //指定寬度 Format('x=%f', [12.0]); //'x=12.00' //浮點(diǎn)數(shù) Format('x=%.3f', [12.0]); //'x=12.000' //指定小數(shù) Format('x=%.*f', [5, 12.0]); //'x=12.00000' //動(dòng)態(tài)配置 Format('x=%.5d', [12]); //'x=00012' //前面補(bǔ)充0 Format('x=%.5x', [12]); //'x=0000C' //十六進(jìn)制 Format('x=%1:d%0:d', [12, 13]); //'x=1312' //使用索引 Format('x=%p', [nil]); //'x=00000000' //指針 Format('x=%1.1e', [12.0]); //'x=1.2E+001' //科學(xué)記數(shù)法 Format('x=%%', []); //'x=%' //得到"%" S := Format('%s%d', [S, I]); //S := S + StrToInt(I); //連接字符串 參考 proceduer SysUtils.FmtStr 例子 Edit1.Text := Format(Edit2.Text, [StrToFloatDef(Edit.3.Text, 0)]); ━━━━━━━━━━━━━━━━━━━━━ 首部 procedure FmtStr(var Result: string; const Format: string; const Args: array of const); $[SysUtils.pas 功能 按指定方式格式化一個(gè)數(shù)組常量的字符形式返回 說(shuō)明 <參見(jiàn)Format> 參考 function SysUtils.FormatBuf;function System.Length;function System.SetLength 例子 <參見(jiàn)Format> ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar; $[SysUtils.pas 功能 返回按指定方式格式化一個(gè)數(shù)組常量的字符指針形式 說(shuō)明 如果Buffer和Format其中只要有一個(gè)為nil則返回nil 參考 function SysUtils.FormatBuf 例子 <參見(jiàn)Format> ━━━━━━━━━━━━━━━━━━━━━ 首部 function StrLFmt(Buffer: PChar; MaxBufLen: Cardinal; Format: PChar; const Args: array of const): PChar; $[SysUtils.pas 功能 返回按指定方式和長(zhǎng)度格式化一個(gè)數(shù)組常量的字符指針形式 說(shuō)明 StrLFmt(vBuffer, 6, '%d|12345', [1024]) = '1024|1'; 參考 function SysUtils.FormatBuf 例子 <參見(jiàn)Format> ━━━━━━━━━━━━━━━━━━━━━ 首部 function FormatBuf(var Buffer; BufLen: Cardinal; const Format; FmtLen: Cardinal; const Args: array of const): Cardinal; $[SysUtils.pas 功能 返回按指定方式格式化一個(gè)數(shù)組常量到緩沖區(qū)Buffer中 說(shuō)明 <NULL> 參考 <NULL> 例子 <參見(jiàn)Format> ━━━━━━━━━━━━━━━━━━━━━ 首部 function WideFormat(const Format: WideString; const Args: array of const): WideString; $[SysUtils.pas 功能 返回按指定方式格式化一個(gè)數(shù)組常量的多字節(jié)字符形式 說(shuō)明 <NULL> 參考 procedure SysUtils.WideFmtStr 例子 <參見(jiàn)Format> ━━━━━━━━━━━━━━━━━━━━━ 首部 procedure WideFmtStr(var Result: WideString; const Format: WideString; const Args: array of const); $[SysUtils.pas 功能 按指定方式格式化一個(gè)數(shù)組常量的多字節(jié)字符形式返回 說(shuō)明 <NULL> 參考 function SysUtils.WideFormatBuf 例子 <參見(jiàn)Format> ━━━━━━━━━━━━━━━━━━━━━ 首部 function WideFormatBuf(var Buffer; BufLen: Cardinal; const Format; FmtLen: Cardinal; const Args: array of const): Cardinal; $[SysUtils.pas 功能 返回按指定方式格式化一個(gè)數(shù)組常量到緩沖區(qū)Buffer中 說(shuō)明 <NULL> 參考 <NULL> 例子 <參見(jiàn)Format> ━━━━━━━━━━━━━━━━━━━━━ 首部 function FloatToStr(Value: Extended): string; $[SysUtils.pas 功能 返回浮點(diǎn)數(shù)Value轉(zhuǎn)換成字符串 說(shuō)明 當(dāng)浮點(diǎn)數(shù)大等于1E15將采用科學(xué)記數(shù)法 參考 function SysUtils.FloatToText 例子 Edit1.Text := FloatToStr(Now); ━━━━━━━━━━━━━━━━━━━━━ 首部 function CurrToStr(Value: Currency): string; $[SysUtils.pas 功能 返回貨幣數(shù)Value轉(zhuǎn)換成字符串 說(shuō)明 貨幣數(shù)只保留四位小數(shù) 參考 function SysUtils.FloatToText 例子 Edit1.Text := CurrToStr(Now); ━━━━━━━━━━━━━━━━━━━━━ 首部 function FloatToCurr(const Value: Extended): Currency; $[SysUtils.pas 功能 返回浮點(diǎn)數(shù)Value轉(zhuǎn)換成貨幣數(shù) 說(shuō)明 如果浮點(diǎn)數(shù)Value超出范圍則將觸發(fā)異常 參考 const SysUtiles.MinCurrency;const SysUtiles.MaxCurrency 例子 Edit1.Text := CurrToStr(FloatToCurr(Now)); ━━━━━━━━━━━━━━━━━━━━━ 首部 function FloatToStrF(Value: Extended; Format: TFloatFormat; Precision, Digits: Integer): string; $[SysUtils.pas 功能 返回浮點(diǎn)數(shù)以指定格式轉(zhuǎn)換成字符串 說(shuō)明 Precision指定精度;Digits指定小數(shù)寬度 參考 function SysUtils.FloatToText 例子 ///////Begin FloatToStrF procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines.Values['ffGeneral'] := FloatToStrF(StrToFloatDef(Edit1.Text, 0), ffGeneral, SpinEdit1.Value, SpinEdit2.Value); Memo1.Lines.Values['ffExponent'] := FloatToStrF(StrToFloatDef(Edit1.Text, 0), ffExponent, SpinEdit1.Value, SpinEdit2.Value); Memo1.Lines.Values['ffFixed'] := FloatToStrF(StrToFloatDef(Edit1.Text, 0), ffFixed, SpinEdit1.Value, SpinEdit2.Value); Memo1.Lines.Values['ffNumber'] := FloatToStrF(StrToFloatDef(Edit1.Text, 0), ffNumber, SpinEdit1.Value, SpinEdit2.Value); Memo1.Lines.Values['ffCurrency'] := FloatToStrF(StrToFloatDef(Edit1.Text, 0), ffCurrency, SpinEdit1.Value, SpinEdit2.Value); end; ///////End FloatToStrF ━━━━━━━━━━━━━━━━━━━━━ 首部 function CurrToStrF(Value: Currency; Format: TFloatFormat; Digits: Integer): string; $[SysUtils.pas 功能 返回貨幣類(lèi)型以指定格式轉(zhuǎn)換成字符串 說(shuō)明 Digits指定小數(shù)寬度 參考 function SysUtils.FloatToText 例子 ///////Begin CurrToStrF procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines.Values['ffGeneral'] := CurrToStrF(StrToCurrDef(Edit1.Text, 0), ffGeneral, SpinEdit1.Value); Memo1.Lines.Values['ffExponent'] := CurrToStrF(StrToCurrDef(Edit1.Text, 0), ffExponent, SpinEdit1.Value); Memo1.Lines.Values['ffFixed'] := CurrToStrF(StrToCurrDef(Edit1.Text, 0), ffFixed, SpinEdit1.Value); Memo1.Lines.Values['ffNumber'] := CurrToStrF(StrToCurrDef(Edit1.Text, 0), ffNumber, SpinEdit1.Value); Memo1.Lines.Values['ffCurrency'] := CurrToStrF(StrToCurrDef(Edit1.Text, 0), ffCurrency, SpinEdit1.Value); end; ///////End CurrToStrF ━━━━━━━━━━━━━━━━━━━━━ 首部 function FloatToText(BufferArg: PChar; const Value; ValueType: TFloatValue; Format: TFloatFormat; Precision, Digits: Integer): Integer; $[SysUtils.pas 功能 返回浮點(diǎn)數(shù)以指定格式轉(zhuǎn)換成指針字符串的內(nèi)存大小 說(shuō)明 Precision指定精度;Digits指定小數(shù)寬度 參考 <NULL> 例子 ///////Begin FloatToText procedure TForm1.Button1Click(Sender: TObject); var vBuffer: array[0..255] of Char; E: Extended; begin E := StrToFloatDef(Edit1.Text, 0); SpinEdit3.Value := FloatToText(vBuffer, E, fvExtended, ffNumber, SpinEdit1.Value, SpinEdit2.Value); Edit2.Text := Copy(vBuffer, 1, SpinEdit3.Value); end; ///////End FloatToText( ━━━━━━━━━━━━━━━━━━━━━ | ||