Delphi常用函數大全(轉)

Abort函數引起放棄的意外處理
Abs函數絕對值函數
AddExitProc函數將一過程添加到運行時庫的結束過程表中
Addr函數返回指定對象的地址
AdjustLineBreaks函數將給定字符串的行分隔符調整爲CR/LF序列
Align屬性使控件位於窗口某部分
Alignment屬性控件標籤的文字位置
AllocMem函數在堆棧上分配給定大小的塊
AllowGrayed屬性允許一個灰度選擇
AnsiCompareStr函數比較字符串(區分大小寫)
AnsiCompareText函數比較字符串(不區分大小寫)
AnsiLowerCase函數將字符轉換爲小寫
AnsiUpperCase函數將字符轉換爲大寫
Append函數以附加的方式打開已有的文件
ArcTan函數餘切函數
AssignFile函數給文件變量賦一外部文件名
Assigned函數測試函數或過程變量是否爲空
AutoSize屬性自動控制標籤的大小
BackgroundColor屬性背景色
BeginThread函數以適當的方式建立用於內存管理的線程
BevelInner屬性控件方框的內框方式
BevelOuter屬性控件方框的外框方式
BevelWidth屬性控件方框的外框寬度
BlockRead函數讀一個或多個記錄到變量中
BlockWrite函數從變量中寫一個或多個記錄
BorderStyle屬性邊界類型
BorderWidth屬性邊界寬度
Break命令終止for、while、repeat循環語句
Brush屬性畫刷
Caption屬性標籤文字的內容
ChangeFileExt函數改變文件的後綴
ChDir函數改變當前目錄
Checked屬性確定複選框選中狀態
Chr函數返回指定序數的字符
CloseFile命令關閉打開的文件
Color屬性標籤的顏色
Columns屬性顯示的列數
CompareStr函數比較字符串(區分大小寫)
Concat函數合併字符串
Continue命令繼續for、while、repeat的下一個循環
Copy函數返回一字符串的子串
Cos函數餘弦函數
Ctl3D屬性是否具有3D效果
Cursor屬性鼠標指針移入後的形狀
Date函數返回當前的日期
DateTimeToFileDate函數將DELPHI的日期格式轉換爲DOS的日期格式
DateTimeToStr函數將日期時間格式轉換爲字符串
DateTimeToString函數將日期時間格式轉換爲字符串
DateToStr函數將日期格式轉換爲字符串
DayOfWeek函數返回星期的數值
Dec函數遞減變量值
DecodeDate函數將日期格式分解爲年月日
DecodeTime函數將時間格式分解爲時、分、秒、毫秒
Delete函數從字符串中刪除子串
DeleteFile命令刪除文件
DiskFree函數返回剩餘磁盤空間的大小
DiskSize函數返回指定磁盤的容量
Dispose函數釋放動態變量所佔的空間
DisposeStr函數釋放字符串在堆棧中的內存空間
DitherBackground屬性使背景色的色彩加重或減少50%
DragCursor屬性當鼠標按下時光標的形狀
DragMode屬性按動的作用方式
DropDownCount屬性容許的顯示數據項的數目
EditMask屬性編輯模式
Enabled屬性是否使標籤呈現打開狀態
EncodeDate函數將年月日合成爲日期格式
EncodeTime函數將時、分、秒、毫秒合成爲時間格式
EndMargin屬性末尾邊緣
Eof函數對有類型或無類型文件測試是否到文件尾
Eoln函數返回文本文件的行結束狀態
Erase命令刪除外部文件
ExceptAddr函數返回引起當前意外的地址
Exclude函數從集合中刪除一些元素
ExceptObject函數返回當前意外的索引
Exit命令立即從當前的語句塊中退出
Exp函數指數函數
ExpandFileName函數返回包含絕對路徑的字符串
ExtendedSelect屬性是否允許存在選擇模式,True時,MultiSelect纔有意義
ExtractFileDir函數返回驅動器和路徑
ExtractFileExt函數返回文件的後綴
ExtractFileName函數返回文件名
ExtractFilePath函數返回指定文件的路徑
FileAge函數返回文件已存在的時間
FileClose命令關閉指定的文件
FileCreate命令用指定的文件名建立新文件
FileDateToDateTime函數將DOS的日期格式轉換爲DELPHI的日期格式
FileExists函數檢查文件是否存在
FileGatAttr函數返回文件的屬性
FileGetDate函數返回文件的DOS日期時間標記
FileOpen命令用指定的存取模式打開指定的文件
FilePos函數返回文件的當前指針位置
FileRead命令從指定的文件讀取
FileSearch命令在目錄中搜索指定的文件
FileSeek函數改變文件的指針
FileSetAttr函數設置文件屬性
FileSetDate函數設置文件的DOS日期時間標記
FileSize函數返回當前文件的大小
FileWrite函數對指定的文件做寫操作
FillChar函數用指定的值填充連續字節的數
FindClose命令終止FindFirst/FindNext序列
FindFirst命令對指定的文件名及屬性搜索目錄
FindNext命令返回與文件名及屬性匹配的下一入口
FloatToDecimal函數將浮點數轉換爲十進制數
FloatToStrF函數將浮點數轉換爲字符串
FloatToStr函數將浮點數轉換爲字符串
FloatToText函數將給定的浮點數轉換爲十進制數
FloatToTextFmt函數將給定的浮點數轉換爲十進制數
Flush函數將緩衝區的內容刷新到輸出的文本文件中
FmtLoadStr函數從程序的資源字符串表中裝載字符串
FmtStr函數格式化一系列的參數,其結果以參數Result返回
Font屬性設置字體
Format函數格式化一系列的參數並返回Pascal字符串
FormatBuf函數格式化一系列的參數
FormatDateTime函數用指定的格式來格式化日期和時間
FormatFloat函數指定浮點數格式
Frac函數返回參數的小數部分
FreeMem函數按給定大小釋放動態變量所佔的空間
GetDir返回指定驅動器的當前目錄
GetHeapStatus返回內存管理器的當前狀態
GetMem建立一指定大小的動態變量,並將指針指向該處
GetMemoryManager返回內存管理器的入口點
Glyph函數按鈕上的圖象
Halt停止程序的執行並返回到操作系統
Hi返回參數的高地址位
High返回參數的上限值
Hint屬性提示信息
Int返回參數的整數部分
Include添加元素到集合中
Insert在字符串中插入子串
IntToHex將整型數轉換爲十六進制數
IntToStr將整型數轉換爲字符串
IOResult返回最新的I/O操作完成狀態
IsValidIdent測試字符串是否爲有效的標識符
Items屬性默認顯示的節點
Kind屬性擺放樣式
LargeChange屬性最大改變值
Layout屬性圖象佈局
Length函數返回字符串的動態長度
Lines屬性缺省顯示內容
Ln函數自然對數函數
Lo函數返回參數的低地址位
LoadStr函數從應用程序的可執行文件中裝載字符資源
LowerCase函數將給定的字符串變爲小寫
Low函數返回參數的下限值
Max屬性最大值
MaxLength屬性最大長度
Min屬性最小值
MkDir命令建立一子目錄
Move函數從源到目標複製字節
MultiSelect屬性允許同時選擇幾個數據項
Name屬性控件的名字
New函數建立新的動態變量並設置一指針變量指向他
NewStr函數在堆棧上分配新的字符串
Now函數返回當前的日期和時間
Odd測試參數是否爲奇數
OnActivate事件焦點移到窗體上時觸發
onClick事件單擊窗體空白區域觸發
OnDblClick事件雙擊窗體空白區域觸發
OnCloseQuery事件使用者試圖關閉窗體觸發
OnClose事件窗體關閉後才觸發
OnCreate事件窗體第一次創建時觸發
OnDeactivate事件用戶切換到另一應用程序觸發
OnDragDrop事件鼠標拖放操作結束時觸發
OnDragOver事件有其他控件從他上面移過觸發
onMouseDown事件按下鼠標鍵時觸發
onMouseUp事件釋放鼠標鍵時觸發
onMouseMove事件移動鼠標時觸發
OnHide事件隱藏窗體時觸發
onKeyDown事件按下鍵盤某鍵時觸發
onKeyPress事件按下鍵盤上的單個字符鍵時觸發
onKeyUp事件釋放鍵盤上的某鍵時觸發
OnPaint事件窗體上有新部分暴露出來觸發
OnResize事件重新調整窗體大小觸發
OnShow事件在窗體實際顯示之前瞬間觸發
Ord返回序數類的序數
OutlineStyle屬性類型
OutOfMemoryError引起OutOfMemory意外
PageIndex屬性頁索引
Pages屬性頁
ParamCount函數返回在命令行上傳遞給程序的參數數量
ParamStr函數返回指定的命令行參數
Pen屬性畫刷設置
Pi函數返回圓周率Pi
Picture屬性顯示圖象
PictureClosed屬性設置Closed位圖
PictureLeaf屬性設置Leaf位圖
PictureMinus屬性設置Minus位圖
PictureOpen屬性設置Open位圖
PicturePlus屬性設置Plus位圖
Pos函數在字符串中搜索子串
Pred函數返回先前的參數
Random函數返回一隨機函數
Randomize函數用一隨機數初始化內置的隨機數生成器
Read函數對有格式的文件,讀一文件組件到變量中;
對文本文件,讀一個或多個值到一個或多個變量中
Readln函數執行Read過程,然後跳到文件下一行
ReadOnly屬性只讀屬性
ReAllocMem函數分配一動態變量
Rename函數重命名外部文件
RenameFile函數對文件重命名
Reset函數打開已有的文件
Rewrite函數建立並打開一新的文件
RmDir函數刪除空的子目錄
Round函數將實數值舍入爲整型值
RunError函數停止程序的執行
ScrollBars屬性滾動條狀態
Seek函數將文件的當前指針移動到指定的組件上
SeekEof函數返回文件的文件結束狀態
SeekEoln函數返回文件的行結束狀態
SelectedColor屬性選中顏色
SetMemoryManager函數設置內存管理器的入口點
SetTextBuf函數給文本文件指定I/O緩衝區
Shape屬性顯示的形狀
ShowException函數顯示意外消息與地址
Sin函數正弦函數
SizeOf函數返回參數所佔的字節數
SmallChange屬性最小改變值
Sorted屬性是否允許排序
Sqr函數平方函數
Sqrt函數平方根函數
StartMargin屬性開始邊緣
State屬性控件當前狀態
Str函數將數值轉換爲字符串
StrAlloc函數給以NULL結束的字符串分配最大長度-1的緩衝區
StrBufSize函數返回存儲在由StrAlloc分配的字符緩衝區的最大字符數
StrCat函數將一字符串附加到另一字符串尾並返回合併的字符串
StrComp函數比較兩個字符串
StrCopy函數將一個字符串複製到另一個字符串中
StrDispose函數釋放堆棧上的字符串
StrECopy函數將一字符串複製到另一個字符串並返回結果字符串尾部的指針
StrEnd函數返回指向字符串尾部的指針
Stretch屬性自動適應控件的大小
StrFmt函數格式化一系列的參數
StrIComp函數比較兩個字符串(不區分大小寫)
StringToWideChar函數將ANSI字符串轉換爲UNICODE字符串
StrLCat函數將一字符串中的字符附加到另一字符串尾並返回合併的字符串
StrLComp函數以最大長度比較兩個字符串
StrLCopy函數將一個字符串中的字符複製到另一個字符串中
StrLen函數返回字符串中的字符數
StrLFmt函數格式化一系列的參數,其結果中包含有指向目標緩衝區的指針
StrLIComp函數以最大長度比較兩個字符串(不區分大小寫)
StrLower函數將字符串中的字符轉換爲小寫
StrMove函數將一個字符串中的字符複製到另一個字符串中
StrNew函數在堆棧上分配一個字符串
StrPas函數將以NULL結束的字符串轉換爲PASCAL類的字符串
StrPCopy函數將PASCAL類的字符串複製爲以NULL結束的字符串
StrPLCopy函數從PASCAL類的最大長度字符串複製爲以NULL結束的字符串
StrPos函數返回一個字符串在另一個字符串中首次出現指針
StrRScan函數返回字符串中最後出現字符的指針
StrScan函數返回字符串中出現首字符的指針
StrToDate函數將字符串轉換爲日期格式
StrToDateTime函數將字符串轉換爲日期/時間格式
StrToFloat函數將給定的字符串轉換爲浮點數
StrToInt函數將字符串轉換爲整型
StrToIntDef函數將字符串轉換爲整型或默認值
StrToTime函數將字符串轉換爲時間格式
StrUpper函數將字符串中的字符轉換爲大寫
Style屬性類型選擇
Suce函數返回後繼的參數
Swap函數交換參數的高低地址位
Tabs屬性標記每一項的內容
TabIndex屬性標記索引
Text屬性顯示的文本
TextToFloat函數將字符串(以NULL結束的格式)轉換爲浮點數
Time函數返回當前的時間
TimeToStr函數將時間格式轉換爲字符串
Trim函數從給定的字符串中刪除前導和尾部的空格及控制字符
TrimLeft函數從給定的字符串中刪除首部的空格及控制字符
TrimRight函數從給定的字符串中刪除尾部的空格及控制字符
Trunc函數將實型值截取爲整型值
Truncate函數截去當前文件位置後的內容
UnSelectedColor屬性未選中顏色
UpCase將字符轉換爲大寫
UpperCase將給定的字符串變爲大寫
Val函數將字符串轉換爲整型值
VarArrayCreate函數以給定的界限和維數建立變體數組
VarArrayDimCount函數返回給定變體的維數
VarArrayHighBound函數返回給定變體數組維數的上界
VarArrayLock函數鎖定給定的變體數組
VarArrayLowBound函數返回給定變體數組維數的下界
VarArrayOf函數返回指定變體的數組元素
VarArrayRedim函數通過改變上限來調整變體的大小
VarArrayUnlock函數解鎖指定的變體數組
VarAsType函數將變體轉換爲指定的類型
VarCase函數將變體轉換爲指定的類型並保存他
VarClear函數清除指定的變體
VarCopy函數將指定的變體複製爲指定的變體
VarFormDateTime函數返回包含日期時間的變體
VarIsArray函數測試變體是否爲數組
VarIsEmpty函數測試變體是否爲UNASSIGNED
VarIsNull函數測試變體是否爲NULL
VarToDateTime函數將給定的變體轉換爲日期時間
VarType函數將變體轉換爲指定的類型並保存他
Visible屬性控件的可見性
WantReturns屬性爲True時,按回車鍵產生一個回車符;
爲False時,按下Ctrl+Enter才產生回車符
Write命令對有格式的文件,寫一變量到文件組件中;
對文本文件,寫一個或多個值到文件中
Writeln命令執行WRITE過程,然後輸出一行結束標誌
WideCharLenToString函數將ANSI字符串轉換爲UNICODE字符串
WideCharLenToStrWar函數將UNICODE字符串轉換爲ANSI字符串變量
WideCharToString函數將UNICODE字符串轉換爲ANSI字符串
WideCharToStrVar函數將UNICODE字符串轉換爲ANSI字符串變量

delphi字符串函數大全
函數 function AnsiResemblesText(const AText, AOther: string): Boolean; $[StrUtils.pas
功能 返回兩個字符串是否相似
說明 ANSI(American National Standards Institute)美國國家標準協會;不區分大小寫
參考 function StrUtils.SoundexProc; var StrUtils.AnsiResemblesProc
例子 CheckBox1.Checked := AnsiResemblesText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiContainsText(const AText, ASubText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否包含子串ASubText
說明 不區分大小寫
參考 function StrUtils.AnsiUppercase; function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStartsText(const ASubText, AText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否以子串ASubText開頭
說明 不區分大小寫
參考 function Windows.CompareString
例子 CheckBox1.Checked := AnsiStartsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiEndsText(const ASubText, AText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否以子串ASubText結尾
說明 不區分大小寫
參考 function Windows.CompareString
例子 CheckBox1.Checked := AnsiEndsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiReplaceText(const AText, AFromText, AToText: string): string; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替換成子串AToText的結果
說明 不區分大小寫
參考 function SysUtils.StringReplace; type SysUtils.TReplaceFlags
例子 Edit4.Text := AnsiReplaceText(Edit1.Text, Edit2.Text, Edit3.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiMatchText(const AText: string; const AValues: array of string): Boolean; $[StrUtils.pas
功能 返回字符串數組AValues中是否包含字符串AText
說明 不區分大小寫
參考 function StrUtils.AnsiIndexText
例子 CheckBox1.Checked := AnsiMatchText(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiIndexText(const AText: string; const AValues: array of string): Integer; $[StrUtils.pas
功能 返回字符串AText在字符串數組AValues中的位置
說明 不區分大小寫;如果不包含則返回-1
參考 function SysUtils.AnsiSameText
例子 SpinEdit1.Value := AnsiIndexText(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiContainsStr(const AText, ASubText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否包含子串ASubText
說明 區分大小寫
參考 function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStartsStr(const ASubText, AText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否以子串ASubText開頭
說明 區分大小寫
參考 function SysUtils.AnsiSameStr
例子 CheckBox1.Checked := AnsiStartsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiEndsStr(const ASubText, AText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否以子串ASubText結尾
說明 區分大小寫
參考 function SysUtils.AnsiSameStr
例子 CheckBox1.Checked := AnsiEndsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiReplaceStr(const AText, AFromText, AToText: string): string; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替換成子串AToText的結果
說明 區分大小寫
參考 function SysUtils.StringReplace; type SysUtils.TReplaceFlags
例子 Edit4.Text := AnsiReplaceStr(Edit1.Text, Edit2.Text, Edit3.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiMatchStr(const AText: string; const AValues: array of string): Boolean; $[StrUtils.pas
功能 返回字符串數組AValues中是否包含字符串AText
說明 區分大小寫
參考 function StrUtils.AnsiIndexStr
例子 CheckBox1.Checked := AnsiMatchStr(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiIndexStr(const AText: string; const AValues: array of string): Integer; $[StrUtils.pas
功能 返回字符串AText在字符串數組AValues中的位置
說明 區分大小寫
參考 function SysUtils.AnsiSameStr
例子 SpinEdit1.Value := AnsiIndexStr(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function DupeString(const AText: string; ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText的ACount個複本
說明 當ACount爲0時返回''
參考 function System.SetLength
例子 Edit3.Text := DupeString(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function ReverseString(const AText: string): string; $[StrUtils.pas
功能 返回字符串AText的反序
說明 ReverseString('1234') = '4321'
參考 function System.SetLength
例子 Edit3.Text := ReverseString(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StuffString(const AText: string; AStart, ALength: Cardinal; const ASubText: string): string; $[StrUtils.pas
功能 返回嵌套字符串
說明 AStart:嵌套開始位置;ALength:嵌套長度;StuffString('abcd', 2, 0, '12') = 'a12bcd'
參考 function System.Copy
例子 Edit3.Text := StuffString(Edit1.Text, SpinEdit1.Value, SpinEdit2.Value, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function RandomFrom(const AValues: array of string): string; overload; $[StrUtils.pas
功能 隨機返回字符串數組AValues中的一個元素
說明 之前建議執行Randomize
參考 function System.Random
例子 Randomize; Edit3.Text := RandomFrom(['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function IfThen(AValue: Boolean; const ATrue: string; AFalse: string = ''): string; overload; $[StrUtils.pas
功能 返回指定的邏輯字符串
說明 IfThen(True, '是', '否') = '是';IfThen(False, '是', '否') = '否'
參考 <NULL>
例子 Edit3.Text := IfThen(CheckBox1.Checked, Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function LeftStr(const AText: string; const ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText左邊的ACount個字符
說明 LeftStr('123456', 3) = '123'
參考 function System.Copy
例子 Edit3.Text := LeftStr(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function RightStr(const AText: string; const ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText右邊的ACount個字符
說明 RightStr('123456', 3) = '456'
參考 function System.Copy
例子 Edit3.Text := RightStr(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function MidStr(const AText: string; const AStart, ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText從AStart開始的ACount個字符
說明 其實就是Copy
參考 function System.Copy
例子 Edit3.Text := MidStr(Edit1.Text, SpinEdit1.Value, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: String; Options: TStringSearchOptions = [soDown]): PChar; $[StrUtils.pas
功能 返回第一個搜索到的指針位置
說明 這函數常用於文本中搜索字符串
參考 <NULL>
例子
///////Begin SearchBuf
function SearchEdit(EditControl: TCustomEdit; const SearchString: String;
SearchOptions: TStringSearchOptions; FindFirst: Boolean = False): Boolean;
var
Buffer, P: PChar;
Size: Word;
begin
Result := False;
if (Length(SearchString) = 0) then Exit;
Size := EditControl.GetTextLen;
if (Size = 0) then Exit;
Buffer := StrAlloc(Size + 1);
try
EditControl.GetTextBuf(Buffer, Size + 1);
P := SearchBuf(Buffer, Size, EditControl.SelStart, EditControl.SelLength,
SearchString, SearchOptions);
if P <> nil then begin
EditControl.SelStart := P - Buffer;
EditControl.SelLength := Length(SearchString);
Result := True;
end;
finally
StrDispose(Buffer);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
SearchOptions: TStringSearchOptions;
begin
SearchOptions := [];
if CheckBox1.Checked then
Include(SearchOptions, soDown);
if CheckBox2.Checked then
Include(SearchOptions, soMatchCase);
if CheckBox3.Checked then
Include(SearchOptions, soWholeWord);
SearchEdit(Memo1, Edit1.Text, SearchOptions);
Memo1.SetFocus;
end;
///////End SearchBuf
━━━━━━━━━━━━━━━━━━━━━
函數 function Soundex(const AText: string; ALength: TSoundexLength = 4): string; $[StrUtils.pas
功能 返回探測字符串
說明 根據探測法(Soundex)可以找到相進的字符串;http://www.nara.gov/genealogy/coding.html
參考 <NULL>
例子 Edit2.Text := Soundex(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexInt(const AText: string; ALength: TSoundexIntLength = 4): Integer; $[StrUtils.pas
功能 返回探測整數
說明 ALength的值越大解碼準確率越高
參考 <NULL>
例子 SpinEdit2.Value := SoundexInt(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function DecodeSoundexInt(AValue: Integer): string; $[StrUtils.pas
功能 返回探測整數的解碼
說明 DecodeSoundexInt(SoundexInt('hello')) 相當於 Soundex('hello')
參考 <NULL>
例子 Edit2.Text := DecodeSoundexInt(SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexWord(const AText: string): Word; $[StrUtils.pas
功能 返回探測文字數值
說明 沒有參數ALength已經固定爲4
參考 <NULL>
例子 SpinEdit2.Value := SoundexWord(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function DecodeSoundexWord(AValue: Word): string; $[StrUtils.pas
功能 返回探測文字數值的解碼
說明 DecodeSoundexWord(SoundexWord('hello')) 相當於 Soundex('hello')
參考 <NULL>
例子 Edit2.Text := DecodeSoundexWord(SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexSimilar(const AText, AOther: string; ALength: TSoundexLength = 4): Boolean; $[StrUtils.pas
功能 返回兩個字符串的探測字符串是否相同
說明 Result := Soundex(AText, ALength) = Soundex(AOther, ALength)
參考 <NULL>
例子 CheckBox1.Checked := SoundexSimilar(Edit1.Text, Edit2.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexCompare(const AText, AOther: string; ALength: TSoundexLength = 4): Integer; $[StrUtils.pas
功能 返回比較兩個字符串的探測字符串的結果
說明 Result := AnsiCompareStr(Soundex(AText, ALength), Soundex(AOther, ALength))
參考 function SysUtils.AnsiCompareStr
例子 SpinEdit2.Value := SoundexCompare(Edit1.Text, Edit2.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexProc(const AText, AOther: string): Boolean; $[StrUtils.pas
功能 調用SoundexSimilar返回兩個字符串的探測字符串是否相同
說明 系統變量AnsiResemblesProc的默認值
參考 function StrUtils.AnsiResemblesText
例子 [var AnsiResemblesProc: TCompareTextProc = SoundexProc;]
━━━━━━━━━━━━━━━━━━━━━
函數 function NewStr(const S: string): PString; deprecated; $[SysUtils.pas
功能 返回一個新的字符串指針地址
說明 字符串S爲空時返回NullStr
參考 procedure System.New
例子
////////Begin NewStr,DisposeStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PString;
begin
P := NewStr(Edit1.Text);
Edit2.Text := P^;
DisposeStr(P);
end;
////////End NewStr,DisposeStr
━━━━━━━━━━━━━━━━━━━━━
函數 procedure DisposeStr(P: PString); deprecated; $[SysUtils.pas
功能 釋放字符串指針P資源
說明 配合函數NewStr使用
參考 procedure System.Dispose
例子 <如上參見,如下參見>
━━━━━━━━━━━━━━━━━━━━━
函數 procedure AssignStr(var P: PString; const S: string); deprecated; $[SysUtils.pas
功能 將字符串S更新給字符串指針P
說明 更新值時會釋放以前字符串指針的資源
參考 function SysUtils.NewStr;function SysUtils.DisposeStr
例子
////////Begin AssignStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PString;
begin
P := nil;
AssignStr(P, Edit1.Text);
Edit2.Text := P^;
DisposeStr(P);
end;
////////End AssignStr
━━━━━━━━━━━━━━━━━━━━━
函數 procedure AppendStr(var Dest: string; const S: string); deprecated; $[SysUtils.pas
功能 在字符串Dest後追加字符串S
說明 相當於Dest := Dest + S;Delphi6已經不建議使用
參考 <NULL>
例子
////////Begin AppendStr
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
begin
S := Edit2.Text;
AppendStr(S, Edit1.Text);
Edit2.Text := S;
end;
////////End AppendStr
━━━━━━━━━━━━━━━━━━━━━
函數 function UpperCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的大寫形式
說明 非小寫字符不處理
參考 procedure System.SetLength
例子 Edit2.Text := UpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function LowerCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的小寫形式
說明 非大寫字符不處理
參考 procedure System.SetLength
例子 Edit2.Text := LowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function CompareStr(const S1, S2: string): Integer; $[SysUtils.pas
功能 返回比較兩個字符
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 <NULL>
例子 SpinEdit1.Value := CompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function CompareMem(P1, P2: Pointer; Length: Integer): Boolean; assembler; $[SysUtils.pas
功能 返回比較兩個內存指針
說明 CompareMem(PChar('12a'), PChar('12c'), 2)=True;CompareMem(PChar('12a'), PChar('12c'), 3)=False
參考 <NULL>
例子 CheckBox1.Checked := CompareMem(Self, Form1, 8);
━━━━━━━━━━━━━━━━━━━━━
函數 function CompareText(const S1, S2: string): Integer; $[SysUtils.pas
功能 返回比較兩個字符串
說明 不區分大小寫
參考 <NULL>
例子 SpinEdit1.Value := CompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function SameText(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個字符串是否相等
說明 不區分大小寫
參考 <NULL>
例子 CheckBox1.Checked := SameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiUpperCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的大寫形式
說明 ANSI(American National Standards Institute)美國國家標準協會;非小寫的字符不變
參考 function Windows.CharUpperBuff
例子 Edit2.Text := AnsiUpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiLowerCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的小寫形式
說明 非大寫字符不處理
參考 function Windows.CharLowerBuff
例子 Edit2.Text := AnsiLowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiCompareStr(const S1, S2: string): Integer; $[SysUtils.pas
功能 反回比較兩個字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiCompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiSameStr(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個字符串是否相等
說明 區分大小寫
參考 function SysUtils.AnsiCompareStr
例子 CheckBox1.Checked := AnsiSameStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiCompareText(const S1, S2: string): Integer; $[SysUtils.pas
功能 反回比較兩個字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiCompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiSameText(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個字符串是否相等
說明 不區分大小寫
參考 function SysUtils.AnsiCompareText
例子 CheckBox1.Checked := AnsiSameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrComp(S1, S2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 function System.CompareString
例子 SpinEdit1.Value := AnsiStrComp(PChar(Edit1.Text), PChar(Edit2.Text))
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrIComp(S1, S2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫;Ignore(忽略)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrIComp(PChar(Edit1.Text), PChar(Edit2.Text))
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrLComp(S1, S2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串指定長度
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫;Length(長度)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrLComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrLIComp(S1, S2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串指定長度
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrLIComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrLower(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串小寫形式
說明 非大寫字符不處理
參考 function Windows.CharLower
例子 Edit2.Text := AnsiStrLower(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrUpper(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串大寫形式
說明 非小寫字符不處理
參考 function Windows.CharUpper
例子 Edit2.Text := AnsiStrUpper(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiLastChar(const S: string): PChar; $[SysUtils.pas
功能 返回字符串S的最後一個指針字符
說明 當字符串S爲空串則返回空指針
參考 function SysUtils.ByteType
例子 Edit2.Text := AnsiLastChar(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrLastChar(P: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串P的最後一個指針字符
說明 當字符串P爲空空指針則返回空指針
參考 function SysUtils.ByteType
例子 Edit2.Text := AnsiLastChar(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function WideUpperCase(const S: WideString): WideString; $[SysUtils.pas
功能 返回雙字節字符串的大寫形式
說明 WideChar雙字節字符
參考 function Windows.CharUpperBuffW
例子 Edit2.Text := WideUpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideLowerCase(const S: WideString): WideString; $[SysUtils.pas
功能 返回雙字節字符串的小寫形式
說明 我怎麼就測試不出來呢
參考 function Windows.CharLowerBuffW
例子 Edit2.Text := WideLowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideCompareStr(const S1, S2: WideString): Integer; $[SysUtils.pas
功能 返回比較兩個雙字節字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 function Windows.CompareStringW
例子 SpinEdit1.Value := WideCompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideSameStr(const S1, S2: WideString): Boolean; $[SysUtils.pas
功能 返回兩個雙字節字符串是否相同
說明 區分大小寫
參考 function SysUtils.WideCompareStr
例子 CheckBox1.Checked := WideSameStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideCompareText(const S1, S2: WideString): Integer; $[SysUtils.pas
功能 返回比較兩個雙字節字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫
參考 function Windows.CompareStringW
例子 SpinEdit1.Value := WideCompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideSameText(const S1, S2: WideString): Boolean; $[SysUtils.pas
功能 返回兩個雙字節字符串是否相同
說明 不區分大小寫
參考 function SysUtils.WideCompareText
例子 CheckBox1.Checked := WideSameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function Trim(const S: string): string; overload; $[SysUtils.pas
函數 function Trim(const S: WideString): WideString; overload; $[SysUtils.pas
功能 返回除去字符串S左右不可見字符
說明 小於#32的字符看作不可見字符
參考 function System.Copy
例子 Edit2.Text := Trim(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function TrimLeft(const S: string): string; overload; $[SysUtils.pas
函數 function TrimLeft(const S: WideString): WideString; overload; $[SysUtils.pas
功能 返回除去字符串S左邊不可見字符
說明 小於#32的字符看作不可見字符
參考 function System.Copy
例子 Edit2.Text := TrimLeft(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function TrimRight(const S: string): string; overload; $[SysUtils.pas
函數 function TrimRight(const S: WideString): WideString; overload; $[SysUtils.pas
功能 返回除去字符串S右邊不可見字符
說明 小於#32的字符看作不可見字符
參考 function System.Copy
例子 Edit2.Text := TrimRight(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function QuotedStr(const S: string): string; $[SysUtils.pas
功能 返回字符串S在pascal中的表現形式
說明 單引號中的一個單引號將轉成兩個
參考 procedure System.Insert
例子 Edit2.Text := QuotedStr(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiQuotedStr(const S: string; Quote: Char): string; $[SysUtils.pas
功能 返回字符串S以字符Quote爲引號的表現形式
說明 AnsiQuotedStr('hello"world', '@')='@hello"world@';AnsiQuotedStr('hello"world', '"')='"hello""world"'
參考 function SysUtils.AnsiStrScan
例子 Edit2.Text := AnsiQuotedStr(Edit1.Text, '"');
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string; $[SysUtils.pas
功能 返回以字符Quote爲引號的表現形式原形
說明 表現形式非法時Src不變否則爲空
參考 function SysUtils.AnsiStrScan
例子
///////Begin AnsiExtractQuotedStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PChar;
begin
P := PChar(Edit1.Text);
Edit2.Text := AnsiExtractQuotedStr(P, '"');
Edit3.Text := P;
end;
///////End AnsiExtractQuotedStr
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiDequotedStr(const S: string; AQuote: Char): string; $[SysUtils.pas
功能 返回以字符AQuote爲引號的表現形式原形
說明 表現形式非法時則返回S
參考 function SysUtils.AnsiExtractQuotedStr
例子 Edit2.Text := AnsiDequotedStr(Edit1.Text, '"');
━━━━━━━━━━━━━━━━━━━━━
函數 function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle = {$IFDEF LINUX} tlbsLF {$ENDIF} {$IFDEF MSWINDOWS} tlbsCRLF {$ENDIF}): string; $[SysUtils.pas
功能 返回將給定字符串的行分隔符調整爲CR/LF序列
說明 AdjustLineBreaks('1'#13'2'#13)='1'#13#10'2'#13#10;AdjustLineBreaks('1'#10'2'#10)='1'#13#10'2'#13#10
參考 function SysUtils.StrNextChar
例子 <NULL>
━━━━━━━━━━━━━━━━━━━━━
函數 function IsValidIdent(const Ident: string): Boolean; $[SysUtils.pas
功能 返回字符串Ident是否是正確的標識符
說明 標識符::字母|下劃線[字母|下劃線|數字]...
參考 <NULL>
例子 CheckBox1.Checked := IsValidIdent(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function IntToStr(Value: Integer): string; overload; $[SysUtils.pas
函數 function IntToStr(Value: Int64): string; overload; $[SysUtils.pas
功能 返回整數Value轉換成字符串
說明 Format('%d', [Value])
參考 function SysUtils.FmtStr
例子 Edit2.Text := IntToStr(SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function IntToHex(Value: Integer; Digits: Integer): string; overload; $[SysUtils.pas
函數 function IntToHex(Value: Int64; Digits: Integer): string; overload; $[SysUtils.pas
功能 返回整數Value轉換成十六進制表現結果;Format('%.*x', [Digits, Value])
說明 參數Digits指定字符最小寬度;最小寬度不足時將用0填充
參考 function SysUtils.FmtStr
例子 Edit2.Text := IntToHex(SpinEdit1.Value, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToInt(const S: string): Integer; $[SysUtils.pas
功能 返回字符串S轉換成整數
說明 字符串非整數表達時將引起異常
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToIntDef(const S: string; Default: Integer): Integer; $[SysUtils.pas
功能 返回字符串S轉換成整數
說明 字符串非整數表達時則返回默認值Default
參考 procedure System.Val
例子 SpinEdit1.Value := StrToIntDef(Edit1.Text, 0);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToInt(const S: string; out Value: Integer): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成整數Value是否成功
說明 字符串非整數表達時返回False並且Value將輸出爲0
參考 procedure System.Val
例子
///////Begin TryStrToInt
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
CheckBox1.Checked := TryStrToInt(Edit1.Text, I);
SpinEdit1.Value := I;
end;
///////End TryStrToInt
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToInt64(const S: string): Int64; $[SysUtils.pas
功能 返回字符串S轉換成六十四位整數
說明 字符串非六十四位整數表達時將引起異常
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt64(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToInt64Def(const S: string; const Default: Int64): Int64; $[SysUtils.pas
功能 返回字符串S轉換成六十四位整數
說明 字符串非六十四位整數表達時則返回默認值Default
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt64Def(Edit1.Text, 0);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToInt64(const S: string; out Value: Int64): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成六十四位整數Value是否成功
說明 字符串非六十四位整數表達時返回False並且Value將輸出爲0
參考 procedure System.Val
例子
///////Begin TryStrToInt64
procedure TForm1.Button1Click(Sender: TObject);
var
I: Int64;
begin
CheckBox1.Checked := TryStrToInt64(Edit1.Text, I);
SpinEdit1.Value := I;
end;
///////End TryStrToInt64
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToBool(const S: string): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成邏輯值
說明 字符非邏輯表達時將引起異常
參考 function SysUtils.TryStrToBool
例子 CheckBox1.Checked := StrToBool(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToBoolDef(const S: string; const Default: Boolean): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成邏輯值
說明 字符非邏輯表達時則返回默認值Default
參考 function SysUtils.TryStrToBool
例子 CheckBox1.Checked := StrToBoolDef(Edit1.Text, False);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToBool(const S: string; out Value: Boolean): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成邏輯值Value是否成功
說明 [注意]0爲假非0爲真;不是'True'和'False';Delphi6 Bug 如下修正
參考 function SysUtils.AnsiSameText;var SysUtils.TrueBoolStrs;var SysUtils.FalseBoolStrs
例子
///////Begin TryStrToBool
procedure TForm1.Button1Click(Sender: TObject);
var
B: Boolean;
begin
SetLength(TrueBoolStrs, 2);
SetLength(FalseBoolStrs, 2);
TrueBoolStrs[0] := 'True';
FalseBoolStrs[0] := 'False';
TrueBoolStrs[1] := 'Yes';
FalseBoolStrs[1] := 'No';
CheckBox1.Checked := TryStrToBool(Edit1.Text, B);
CheckBox2.Checked := B;
end;
///////End TryStrToBool
附加
///////Begin TryStrToBool
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
function CompareWith(const aArray: array of string): Boolean;
var
I: Integer;
begin
Result := False;
for I := Low(aArray) to High(aArray) do
if AnsiSameText(S, aArray[I]) then
begin
Result := True;
Break;
end;
end;
var
LResult: Extended;
begin
Result := TryStrToFloat(S, LResult);
if Result then
Value := LResult <> 0
else
begin
Result := True; //修正處
VerifyBoolStrArray;
if CompareWith(TrueBoolStrs) then
Value := True
else if CompareWith(FalseBoolStrs) then
Value := False
else
Result := False;
end;
end;
///////End TryStrToBool
━━━━━━━━━━━━━━━━━━━━━
函數 function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string; $[SysUtils.pas
功能 返回邏輯值B轉換成字符串
說明 BoolToStr(False, False)='0';BoolToStr(False, True)='-1'
參考 var SysUtils.TrueBoolStrs;var SysUtils.FalseBoolStrs
例子 Edit1.Text := BoolToStr(CheckBox1.Checked, CheckBox2.Checked);
━━━━━━━━━━━━━━━━━━━━━
函數 function LoadStr(Ident: Integer): string; $[SysUtils.pas
功能 返回根據標識Ident的字符串資源
說明 字符串資源是指程序的內部資源
參考 function SysUtils.FindStringResource
例子 Edit2.Text := LoadStr(StrToIntDef(Edit1.Text, 0));
━━━━━━━━━━━━━━━━━━━━━
函數 function FmtLoadStr(Ident: Integer; const Args: array of const): string; $[SysUtils.pas
功能 返回格式化的字符串資源
說明 字符串資源是指程序的內部資源
參考 function SysUtils.FmtStr;function SysUtils.FindStringResource
例子 <NULL>;
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLen(const Str: PChar): Cardinal; $[SysUtils.pas
功能 返回指針字符串的長度
說明 當指針字符串Str爲nil時將觸發異常
參考 <NULL>
例子 SpinEdit2.Value := StrLen(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrEnd(const Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串的結尾
說明 當指針字符串Str爲nil時將觸發異常
參考 <NULL>
例子 Edit2.Text := StrEnd(PChar(Edit1.Text)) - SpinEdit1.Value;
━━━━━━━━━━━━━━━━━━━━━
函數 function StrMove(Dest: PChar; const Source: PChar; Count: Cardinal): PChar; $[SysUtils.pas
功能 返回將指針字符串Source指定內存數量Count複製覆蓋到指針字符串Dest中
說明 Dest沒有分配資源將觸發異常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複製到指針字符串Dest中
說明 Dest應已經分配足夠的空間非則將觸發異常
參考 <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複製到指針字符串Dest中的結尾
說明 可以連接指針字符串
參考 <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指定長度MaxLen複製到指針字符串Dest中
說明 Dest應已經分配足夠的空間非則將觸發異常
參考 <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複製到指針字符串Dest中
說明 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指定長度MaxLen複製到指針字符串Dest中
說明 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
說明 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
說明 [注意]MaxLen指定連接後的最大長度不是指針字符串Source的長度
參考 <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
功能 返回比較兩個指針字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫;[注意]返回第一個出現不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrComp(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrIComp(const Str1, Str2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫;[注意]返回第一個出現不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrIComp(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串指定長度
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫;Length(長度);[注意]返回第一個出現不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrLComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLIComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串指定長度
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫;[注意]返回第一個出現不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrLIComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
函數 function StrScan(const Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr第一個出現的地址
說明 沒有找到則返回空指針
參考 <NULL>
例子 Edit2.Text := StrScan(PChar(Edit1.Text), '*');
━━━━━━━━━━━━━━━━━━━━━
函數 function StrRScan(const Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr最後一個出現的地址
說明 沒有找到則返回空指針
參考 <NULL>
例子 Edit2.Text := StrRScan(PChar(Edit1.Text), '*');
━━━━━━━━━━━━━━━━━━━━━
函數 function StrPos(const Str1, Str2: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串Str2在Str1中第一個出現的地址
說明 沒有找到則返回空指針;StrPos('12345', '3') = '345'
參考 <NULL>
例子 Edit3.Text := StrPos(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrUpper(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串Str大寫
說明 非小寫字符不處理
參考 <NULL>
例子 Edit1.Text := StrUpper(PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLower(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串Str小寫
說明 非大寫字符不處理
參考 <NULL>
例子 Edit1.Text := StrLower(PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrPas(const Str: PChar): string; $[SysUtils.pas
功能 返回指針字符串Str轉換成字符串
說明 也可以直接賦值
參考 <NULL>
例子 Edit1.Text := StrPas(PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrAlloc(Size: Cardinal): PChar; $[SysUtils.pas
功能 返回分配指定空間的內存資源給指針字符串
說明 空間的大小也將保存;用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
功能 返回通過函數StrAlloc分配的緩衝區大小
說明 出現異常情況則返回不可預知的結果
參考 function System.SizeOf
例子 SpinEdit1.Value := StrBufSize(StrAlloc(SpinEdit2.Value));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrNew(const Str: PChar): PChar; $[SysUtils.pas
功能 返回複製一個新的指針字符串
說明 如果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內存資源
說明 如果Str爲nil則不作任何處理;並且釋放空間大小信息
參考 function System.Dec;function System.SizeOf;function System.FreeMem
例子 <參見StrNew>
━━━━━━━━━━━━━━━━━━━━━
函數 function Format(const Format: string; const Args: array of const): string; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量的字符形式
說明 這個函數是我在Delphi中用得最多的函數,現在就列舉幾個例子給你個直觀的理解
"%" [索引 ":"] ["-"] [寬度] ["." 摘要] 類型
Format('x=%d', [12]); //'x=12' //最普通
Format('x=%3d', [12]); //'x= 12' //指定寬度
Format('x=%f', [12.0]); //'x=12.00' //浮點數
Format('x=%.3f', [12.0]); //'x=12.000' //指定小數
Format('x=%.*f', [5, 12.0]); //'x=12.00000' //動態配置
Format('x=%.5d', [12]); //'x=00012' //前面補充0
Format('x=%.5x', [12]); //'x=0000C' //十六進制
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' //科學記數法
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
功能 按指定方式格式化一個數組常量的字符形式返回
說明 <參見Format>
參考 function SysUtils.FormatBuf;function System.Length;function System.SetLength
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量的字符指針形式
說明 如果Buffer和Format其中只要有一個爲nil則返回nil
參考 function SysUtils.FormatBuf
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLFmt(Buffer: PChar; MaxBufLen: Cardinal; Format: PChar; const Args: array of const): PChar; $[SysUtils.pas
功能 返回按指定方式和長度格式化一個數組常量的字符指針形式
說明 StrLFmt(vBuffer, 6, '%d|12345', [1024]) = '1024|1';
參考 function SysUtils.FormatBuf
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function FormatBuf(var Buffer; BufLen: Cardinal; const Format; FmtLen: Cardinal; const Args: array of const): Cardinal; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量到緩衝區Buffer中
說明 <NULL>
參考 <NULL>
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function WideFormat(const Format: WideString; const Args: array of const): WideString; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量的多字節字符形式
說明 <NULL>
參考 procedure SysUtils.WideFmtStr
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 procedure WideFmtStr(var Result: WideString; const Format: WideString; const Args: array of const); $[SysUtils.pas
功能 按指定方式格式化一個數組常量的多字節字符形式返回
說明 <NULL>
參考 function SysUtils.WideFormatBuf
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function WideFormatBuf(var Buffer; BufLen: Cardinal; const Format; FmtLen: Cardinal; const Args: array of const): Cardinal; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量到緩衝區Buffer中
說明 <NULL>
參考 <NULL>
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function FloatToStr(Value: Extended): string; $[SysUtils.pas
功能 返回浮點數Value轉換成字符串
說明 當浮點數大等於1E15將採用科學記數法
參考 function SysUtils.FloatToText
例子 Edit1.Text := FloatToStr(Now);
━━━━━━━━━━━━━━━━━━━━━
函數 function CurrToStr(Value: Currency): string; $[SysUtils.pas
功能 返回貨幣數Value轉換成字符串
說明 貨幣數只保留四位小數
參考 function SysUtils.FloatToText
例子 Edit1.Text := CurrToStr(Now);
━━━━━━━━━━━━━━━━━━━━━
函數 function FloatToCurr(const Value: Extended): Currency; $[SysUtils.pas
功能 返回浮點數Value轉換成貨幣數
說明 如果浮點數Value超出範圍則將觸發異常
參考 const SysUtiles.MinCurrency;const SysUtiles.MaxCurrency
例子 Edit1.Text := CurrToStr(FloatToCurr(Now));
━━━━━━━━━━━━━━━━━━━━━
函數 function FloatToStrF(Value: Extended; Format: TFloatFormat; Precision, Digits: Integer): string; $[SysUtils.pas
功能 返回浮點數以指定格式轉換成字符串
說明 Precision指定精度;Digits指定小數寬度
參考 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
功能 返回貨幣類型以指定格式轉換成字符串
說明 Digits指定小數寬度
參考 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
功能 返回浮點數以指定格式轉換成指針字符串的內存大小
說明 Precision指定精度;Digits指定小數寬度
參考 <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(
━━━━━━━━━━━━━━━━━━━━━
函數 function FormatFloat(const Format: string; Value: Extended): string; $[SysUtils.pas
功能 返回浮點數類型以指定格式字符串Format轉換成字符串
說明 FormatFloat(',.00', 1234567890) = '1,234,567,890.00'
參考 function SysUtils.FloatToTextFmt
例子 Edit1.Text := FormatFloat(Edit2.Text, StrToFloatDef(Edit3.Text, 0));
━━━━━━━━━━━━━━━━━━━━━
函數 function FormatCurr(const Format: string; Value: Currency): string; $[SysUtils.pas
功能 返回貨幣類型以指定格式字符串Format轉換成字符串
說明 FormatCurr(',.00', 1234567890) = '1,234,567,890.00'
參考 function SysUtils.FloatToTextFmt
例子 Edit1.Text := FormatCurr(Edit2.Text, StrToCurrDef(Edit3.Text, 0));
━━━━━━━━━━━━━━━━━━━━━
函數 function FloatToTextFmt(Buf: PChar; const Value; ValueType: TFloatValue; Format: PChar): Integer; $[SysUtils.pas
功能 返回浮點數以指定格式字符串Format轉換成指針字符串的內存大小
說明 ValueType指定無類型參數Value的類型
參考 <NULL>
例子
///////Begin FloatToTextFmt
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: array[0..255] of Char;
E: Extended;
begin
E := StrToFloatDef(Edit1.Text, 0);
SpinEdit1.Value := FloatToTextFmt(vBuffer, E,
fvExtended, PChar(Edit2.Text));
Edit3.Text := Copy(vBuffer, 1, SpinEdit1.Value);
end;
///////End FloatToTextFmt
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToFloat(const S: string): Extended; $[SysUtils.pas
功能 返回字符串S轉換成浮點數
說明 字符串非浮點數表達時將引起異常
參考 function SysUtils.TextToFloat
例子 var E: Extended; begin E := StrToFloat(Edit1.Text); end;
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToFloatDef(const S: string; const Default: Extended): Extended; $[SysUtils.pas
功能 返回字符串S轉換成浮點數
說明 字符串非浮點數表達時則返回默認值Default
參考 function SysUtils.TextToFloat
例子 var E: Extended; begin E := StrToFloatDef(Edit1.Text, 0); end;
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToFloat(const S: string; out Value: Extended): Boolean; overload; $[SysUtils.pas
函數 function TryStrToFloat(const S: string; out Value: Single): Boolean; overload; $[SysUtils.pas
函數 function TryStrToFloat(const S: string; out Value: Double): Boolean; overload; $[SysUtils.pas
功能 返回字符串S轉換成浮點數Value是否成功
說明 字符串非浮點數表達時返回False並且Value將輸出爲不確定的值
參考 function SysUtils.TextToFloat
例子
///////Begin TryStrToFloat
procedure TForm1.Button1Click(Sender: TObject);
var
E: Extended;
begin
CheckBox1.Checked := TryStrToFloat(Edit1.Text, E);
Edit2.Text := FormatFloat('', E);
end;
///////End TryStrToFloat
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToCurr(const S: string): Currency; $[SysUtils.pas
功能 返回字符串S轉換成貨幣數
說明 字符串非貨幣數表達時將引起異常
參考 function SysUtils.TextToFloat
例子 var C: Currency; begin C := StrToCurr(Edit1.Text); end;
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToCurrDef(const S: string; const Default: Currency): Currency; $[SysUtils.pas
功能 返回字符串S轉換成貨幣數
說明 字符串非貨幣數表達時則返回默認值Default
參考 function SysUtils.TextToFloat
例子 var C: Currency; begin C := StrToCurrDef(Edit1.Text, 0); end;
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToCurr(const S: string; out Value: Currency): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成貨幣數Value是否成功
說明 字符串非貨幣數表達時返回False並且Value將輸出爲不確定的值
參考 function SysUtils.TextToFloat
例子
///////Begin TryStrToCurr
procedure TForm1.Button1Click(Sender: TObject);
var
C: Currency;
begin
CheckBox1.Checked := TryStrToCurr(Edit1.Text, C);
Edit2.Text := FormatCurr('', C);
end;
///////End TryStrToCurr
━━━━━━━━━━━━━━━━━━━━━
函數 function TextToFloat(Buffer: PChar; var Value; ValueType: TFloatValue): Boolean; $[SysUtils.pas
功能 返回將指針字符串Buffer轉換成無類型變量Value
說明 ValueType指定無類型參數Value的類型
參考 <NULL>
例子
///////Begin TextToFloat
procedure TForm1.Button1Click(Sender: TObject);
var
E: Extended;
begin
CheckBox1.Checked := TextToFloat(PChar(Edit1.Text), E,
fvExtended);
Edit2.Text := FormatFloat('', E);
end;
///////End TextToFloat
━━━━━━━━━━━━━━━━━━━━━
函數 function DateToStr(const DateTime: TDateTime): string; $[SysUtils.pas
功能 返回日期DateTime轉換成字符串
說明 轉換格式由系統變量ShortDateFormat控制
參考 function SysUtils.DateTimeToString;var SysUtils.ShortDateFormat
例子 Edit1.Text := DateToStr(Date);
━━━━━━━━━━━━━━━━━━━━━
函數 function TimeToStr(const DateTime: TDateTime): string; $[SysUtils.pas
功能 返回時間DateTime轉換成字符串
說明 轉換格式由系統變量LongTimeFormat控制
參考 function SysUtils.DateTimeToString;var SysUtils.LongTimeFormat
例子 Edit1.Text := TimeToStr(Date);
━━━━━━━━━━━━━━━━━━━━━
函數 function DateTimeToStr(const DateTime: TDateTime): string; $[SysUtils.pas
功能 返回日期時間DateTime轉換成字符串
說明 轉換格式由系統變量ShortDateFormat和LongTimeFormat控制
參考 function SysUtils.DateTimeToString
例子 Edit1.Text := DateTimeToStr(Now);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToDate(const S: string): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成日期
說明 字符非日期表達時將引起異常
參考 function SysUtils.TryStrToDate
例子 DateTimePicker1.Date := StrToDate(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToDateDef(const S: string; const Default: TDateTime): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成日期
說明 字符非日期表達時則返回默認值Default
參考 function SysUtils.TryStrToDate
例子 DateTimePicker1.Date := StrToDateDef(Edit1.Text, Date);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToDate(const S: string; out Value: TDateTime): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成日期Value是否成功
說明 字符非日期表達時返回False並且Value將輸出爲0
參考 <NULL>
例子
///////Begin TryStrToDate
procedure TForm1.Button1Click(Sender: TObject);
var
vDateTime: TDateTime;
begin
CheckBox1.Checked := TryStrToDate(Edit1.Text, vDateTime);
DateTimePicker1.Date := vDateTime;
end;
///////End TryStrToDate
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToTime(const S: string): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成時間
說明 字符非時間表達時將引起異常
參考 function SysUtils.TryStrToTime
例子 DateTimePicker1.Time := StrToTime(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToTimeDef(const S: string; const Default: TDateTime): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成時間
說明 字符非時間表達時則返回默認值Default
參考 function SysUtils.TryStrToTime
例子 DateTimePicker1.Time := StrToTimeDef(Edit1.Text, Time);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToTime(const S: string; out Value: TDateTime): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成時間Value是否成功
說明 字符非時間表達時返回False並且Value將輸出爲0
參考 <NULL>
例子
///////Begin TryStrToTime
procedure TForm1.Button1Click(Sender: TObject);
var
vDateTime: TDateTime;
begin
CheckBox1.Checked := TryStrToTime(Edit1.Text, vDateTime);
DateTimePicker1.Time := vDateTime;
end;
///////End TryStrToTime
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToDateTime(const S: string): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成日期時間
說明 字符非日期時間表達時將引起異常
參考 function SysUtils.TryStrToDateTime
例子 Edit1.Text := DateTimeToStr(StrToDateTime(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToDateTimeDef(const S: string; const Default: TDateTime): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成日期時間
說明 字符非日期時間表達時則返回默認值Default
參考 function SysUtils.TryStrToDateTime
例子 Edit1.Text := DateTimeToStr(StrToDateTimeDef(Edit2.Text, Now));
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成日期時間Value是否成功
說明 字符非日期時間表達時返回False並且Value將輸出爲0
參考 <NULL>
例子
///////Begin TryStrToDateTime
procedure TForm1.Button1Click(Sender: TObject);
var
vDateTime: TDateTime;
begin
CheckBox1.Checked := TryStrToDateTime(Edit1.Text, vDateTime);
Edit2.Text := DateTimeToStr(vDateTime);
end;
///////End TryStrToDateTime
━━━━━━━━━━━━━━━━━━━━━
函數 procedure DateTimeToString(var Result: string; const Format: string; DateTime: TDateTime); $[SysUtils.pas
功能 用指定的格式Format來格式化日期時間DateTime並返回到字符串Result中
說明 <參見FormatDateTime>
參考 function System.SetString
例子 <參見FormatDateTime>
━━━━━━━━━━━━━━━━━━━━━
函數 function GetLocaleStr(Locale, LocaleType: Integer; const Default: string): string; platform; $[SysUtils.pas
功能 返回當前系統指定參數的字符串值
說明 GetLocaleStr(GetThreadLocale, LOCALE_SLANGUAGE, '') = '中文(中國)'
參考 function Windows.GetLocaleInfo
例子 Edit1.Text := GetLocaleStr(GetThreadLocale, SpinEdit1.Value, '<NULL>');
━━━━━━━━━━━━━━━━━━━━━
函數 function GetLocaleChar(Locale, LocaleType: Integer; Default: Char): Char; platform; $[SysUtils.pas
功能 返回當前系統指定參數的字符值
說明 GetLocaleChar(GetThreadLocale, LOCALE_STHOUSAND, #0) = ','
參考 function Windows.GetLocaleInfo
例子 Edit1.Text := GetLocaleChar(GetThreadLocale, LOCALE_SLANGUAGE, #0);
━━━━━━━━━━━━━━━━━━━━━
函數 function ByteType(const S: string; Index: Integer): TMbcsByteType; $[SysUtils.pas
功能 返回字符串S位置Index上的字符在MBCS中類型
說明 多字節字符系統:Multi-Byte Character System (MBCS)
參考 var SysUtils.SysLocale
例子 SpinEdit1.Value := Ord(ByteType(Edit1.Text, SpinEdit2.Value));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType; $[SysUtils.pas
功能 返回指針字符串Str位置Index上的字符在MBCS中類型
說明 Index從0開始
參考 var SysUtils.SysLocale
例子 SpinEdit1.Value := Ord(StrByteType(PChar(Edit1.Text), SpinEdit2.Value));
━━━━━━━━━━━━━━━━━━━━━
函數 function ByteToCharLen(const S: string; MaxLen: Integer): Integer; $[SysUtils.pas
功能 返回字符串S中有多少個多字節字符
說明 MaxLen指定處理字符個數
參考 function SysUtils.ByteToCharIndex
例子 SpinEdit1.Value := ByteToCharLen(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function CharToByteLen(const S: string; MaxLen: Integer): Integer; $[SysUtils.pas
功能 返回字符串S中有多少個字符
說明 MaxLen指定處理多字節字符個數
參考 var SysUtils.SysLocale
例子 SpinEdit1.Value := CharToByteLen(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function ByteToCharIndex(const S: string; Index: Integer): Integer; $[SysUtils.pas
功能 返回字符位置對應的多字節字符位置
說明 ByteToCharIndex('你好', 2) = 1;ByteToCharIndex('你好', 3) = 2
參考 function SysUtils.NextCharIndex
例子 SpinEdit1.Value := ByteToCharIndex(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function CharToByteIndex(const S: string; Index: Integer): Integer; $[SysUtils.pas
功能 返回多字節字符位置對應的字符起始位置
說明 CharToByteIndex('你好', 1) = 1;CharToByteIndex('你好', 2) = 3
參考 function System.Length
例子 SpinEdit1.Value := CharToByteIndex(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrCharLength(const Str: PChar): Integer; $[SysUtils.pas
功能 返回第一個字符的寬度
說明 參數爲空則返回0
參考 function Windows.CharNext
例子 SpinEdit1.Value := StrCharLength(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrNextChar(const Str: PChar): PChar; $[SysUtils.pas
功能 返回字符指針Str的下一個字符指針
說明 StrNextChar('1234') = '234';
參考 function Windows.CharNext
例子 Edit2.Text := StrNextChar(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function CharLength(const S: String; Index: Integer): Integer; $[SysUtils.pas
功能 返回字符串中指定位置的字符寬度
說明 CharLength('English漢', 1) = 1;CharLength('English漢', 8) = 2
參考 function System.Assert;function SysUtils.StrCharLength
例子 SpinEdit1.Value := CharLength(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function NextCharIndex(const S: String; Index: Integer): Integer; $[SysUtils.pas
功能 返回下一個字符的位置
說明 CharLength('你好', 1) = 3;CharLength('你好', 3) = 5
參考 function System.Assert;function SysUtils.StrCharLength
例子 SpinEdit1.Value := NextCharIndex(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function IsPathDelimiter(const S: string; Index: Integer): Boolean; $[SysUtils.pas
功能 返回字符串S中指定位置Index上是否是一個路徑分隔符
說明 IsPathDelimiter('C:/Windows', 3) = True
參考 const SysUtils.PathDelim;function SysUtils.ByteType
例子 CheckBox1.Checked := IsPathDelimiter(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean; $[SysUtils.pas
功能 返回字符串S中指定位置Index上是否是一個分隔符Delimiters
說明 IsDelimiter('@', '[email protected]', 8) = True
參考 function SysUtils.ByteType
例子 CheckBox1.Checked := IsDelimiter(Edit1.Text, Edit2.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function IncludeTrailingPathDelimiter(const S: string): string; $[SysUtils.pas
功能 返回包括最後路徑分隔符
說明 最後一個字符是路徑分隔符則不變;否則加上一個路徑分隔符返回
參考 function SysUtils.IsPathDelimiter;function System.Length
例子 Edit1.Text := IncludeTrailingPathDelimiter(Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function IncludeTrailingBackslash(const S: string): string; platform; $[SysUtils.pas
功能 返回包括最後斜線
說明 Result := IncludeTrailingPathDelimiter(S);
參考 function SysUtils.IncludeTrailingPathDelimiter
例子 Edit1.Text := IncludeTrailingBackslash(Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function ExcludeTrailingPathDelimiter(const S: string): string; $[SysUtils.pas
功能 返回排除最後路徑分隔符
說明 最後一個字符不是路徑分隔符則不變;否則減去最後的路徑分隔符返回
參考 function SysUtils.IsPathDelimiter;function System.Length;function System.SetLength
例子 Edit1.Text := ExcludeTrailingPathDelimiter(Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function ExcludeTrailingBackslash(const S: string): string; platform; $[SysUtils.pas
功能 返回排除最後斜線
說明 Result := ExcludeTrailingPathDelimiter(S)
參考 function SysUtils.ExcludeTrailingPathDelimiter
例子 Edit1.Text := ExcludeTrailingBackslash(Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function LastDelimiter(const Delimiters, S: string): Integer; $[SysUtils.pas
功能 返回最後一個分隔符的位置
說明 LastDelimiter('.', 'kingron.myetang.com') = 16
參考 function SysUtils.StrScan;function SysUtils.ByteType
例子 SpinEdit1.Value := LastDelimiter(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiCompareFileName(const S1, S2: string): Integer; $[SysUtils.pas
功能 返回比較兩個文件名
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 function SysUtils.AnsiCompareStr
例子 SpinEdit1.Value := AnsiCompareFileName(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function SameFileName(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個文件名是否相等
說明 區分大小寫
參考 function SysUtils.AnsiCompareFileName
例子 CheckBox1.Checked := SameFileName(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiLowerCaseFileName(const S: string): string; $[SysUtils.pas
功能 返回小寫文件名
說明 在非多字節字符系統上相當於AnsiLowerCase
參考 function SysUtils.AnsiLowerCase
例子 Edit2.Text := AnsiLowerCaseFileName(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiUpperCaseFileName(const S: string): string; $[SysUtils.pas
功能 返回大寫文件名
說明 在非多字節字符系統上相當於AnsiUpperCase
參考 function SysUtils.AnsiUpperCase
例子 Edit2.Text := AnsiUpperCaseFileName(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiPos(const Substr, S: string): Integer; $[SysUtils.pas
功能 返回子串Substr在字符中第一次出現的位置
說明 不存在則返回0
參考 SysUtils.AnsiStrPos
例子 SpinEdit1.Value := AnsiPos(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrPos(Str, SubStr: PChar): PChar; $[SysUtils.pas
功能 返回指針子串Substr在指針字符中第一次出現的指針位置
說明 不存在則返回nil
參考 function SysUtils.StrByteType
例子 Edit3.Text := AnsiStrPos(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrRScan(Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr最後一個出現的地址
說明 支持多字節字符系統;AnsiStrRScan('kingron.myetang.com', '.') = '.com'
參考 function SysUtils.AnsiStrScan
例子 Edit2.Text := AnsiStrScan(PChar(Edit1.Text), '.');
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrScan(Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr第一個出現的地址
說明 支持多字節字符系統;AnsiStrRScan('kingron.myetang.com', '.') = '.myetang.com'
參考 function SysUtils.StrScan
例子 Edit2.Text := AnsiStrScan(PChar(Edit1.Text), '.');

━━━━━━━━━━━━━━━━━━━━━
函數 function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string; $[SysUtils.pas
功能 返回替換後的字符串
說明 rfReplaceAll爲替換全部內容;rfIgnoreCase爲忽略大小寫
參考 function SysUtils.AnsiUpperCase;function SysUtils.AnsiPos;function System.Copy
例子
///////Begin StringReplace
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Values['[]'] :=
StringReplace(Edit1.Text, Edit2.Text, Edit3.Text, []);
Memo1.Lines.Values['[rfReplaceAll]'] :=
StringReplace(Edit1.Text, Edit2.Text, Edit3.Text, [rfReplaceAll]);
Memo1.Lines.Values['[rfIgnoreCase]'] :=
StringReplace(Edit1.Text, Edit2.Text, Edit3.Text, [rfIgnoreCase]);
Memo1.Lines.Values['[rfReplaceAll, rfIgnoreCase]'] :=
StringReplace(Edit1.Text, Edit2.Text, Edit3.Text, [rfReplaceAll, rfIgnoreCase]);
end;
///////End StringReplace
━━━━━━━━━━━━━━━━━━━━━
函數 function StringToGUID(const S: string): TGUID; $[SysUtils.pas
功能 返回字符串S轉換成全局標識
說明 如果字符串非法將觸發異常
參考 fuction Windows.Succeeded
例子 Edit2.Text := GUIDToString(StringToGUID(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function GUIDToString(const GUID: TGUID): string; $[SysUtils.pas
功能 返回全局標識GUID轉換成字符串
說明 <NULL>
參考 fuction Windows.Succeeded
例子 Edit2.Text := GUIDToString(StringToGUID(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━

=================================================
日期與時間函數 (Date and Time Routines)
Unit: SysUtils
========================================
Date 傳回今天日期。function Date: TDateTime;
DateTimeToStr 將時間格式轉爲字串。function DateTimeToStr(DateTime: TDateTime):String;
DateTimeToString 將時間格式轉爲字串。
procedure DateTimeToString(var Result: string;const Format: string;DateTime: TDateTime);
DateToStr 將日期格式轉爲字串。function DateToStr(Date: TDateTime): String;
DayOfWeek 傳回今天星期幾。function DayOfWeek(Date: TDateTime): Integer;
DecodeDate 分解所指定的日期爲年、月、日。
procedure DecodeDate(Date: TDateTime;var Year, Month, Day:Word);
DecodeTime 分解所指定的日期爲時、分、秒。
procedure DecodeTime(Time: TDateTime;var Hour, Min, Sec,MSec: Word);
EncodeDate 傳回將年、月、日所組合的日期格式。
function EncodeDate(Year, Month, Day: Word):TDateTime;
EncodeTime 傳回將時、分、秒所組合的時間格式。
function EncodeTime(Hour, Min, Sec, MSec:Word): TDateTime;
FormatDateTime 以指定的格式傳回日期時間。
function FormatDateTime(const Format: string;DateTime: TDateTime):String;
Now 傳回現在的日期時間。function Now: TDateTime;
StrToDate 將字串轉爲日期格式。function StrToDate(const S:string): TDateTime;
StrToDateTime 將字串轉爲日期時間格式function StrToDateTime(const S: string): TDateTime;
StrToTime 將字串轉爲時間格式。function StrToTime(const S:string): TDateTime;
Time 傳回現在時間。function Time: TDateTime;
TimeToStr 將時格式轉爲字串。function TimeToStr(Time:TDateTime): String;
========================================
檔案管理函數
Unit: SysUtils
========================================
ChangeFileExt 變更檔案的延伸檔名。
function ChangeFileExt(const FileName,Extension: string):string;
DateTimeToFileDate 將Delphi 的日期格式轉換爲DOS的日期格式。
functionDateTimeToFileDate(DateTime:TDateTime): Longint;
DeleteFile 刪除一個檔案。
function DeleteFile(const FileName: string):Boolean;
DiskFree 傳回磁碟的可用空間。function DiskFree(Drive: Byte): Longint;
DiskSize 傳回指定磁碟的容量大小。function DiskSize(Drive: Byte): Longint;
ExpandFileName 傳回一個完整的路徑及檔名字串。
function expandFileName(const FileName: string):string;
ExtractFileExt 傳回檔案的延伸檔名。function ExtractFileExt(const FileName string):string;
ExtractFileName 傳回檔案的檔名。function ExtractFileName(const FileName: string):string;
ExtractFilePath 傳回檔案的路徑。function ExtractFilePath(const FileName: string):string;
FileAge 傳回檔案的年紀function FileAge(const FileName: string):Longint;
FileCreate 以指定檔名建立一個檔案。function FileCreate(const FileName: string):Integer;
FileClose 關閉指定的檔案。procedureFileClose(Handle: Integer);
FileDateToDateTime 將DOS 的日期格式轉爲Delphi 的日期格式。
function FileDateToDateTime(FileDate: Longint):TDateTime;
FileExists 判別檔案是否存在。function FileExists(const FileName: string):Boolean;
FileGetAttr 傳回檔案屬性。function FileGetAttr(const FileName: string):Integer;
FileGetDate 傳回檔案的日期及時間。function FileGetDate(Handle: Integer): Longint;
FileRead 從指定的檔案讀入資料。
function FileRead(Handle:Integer; var Buffer;Count:Longint):Longint;
FileSearch 在目錄列中搜尋指定的檔案。function FileSearch(constName, DirList: string):string;
FileSeek 改變檔案遊標的位置。function FileSeek(Handle: Integer;Offset: Longint;Origin: Integer):Longint;
FileSetAttr 設定檔案屬性。function FileSetAttr(const FileName: string;Attr:Integer): Integer;
FileSetDate 設定檔案的日期及時間。procedure FileSetDate(Handle: Integer; Age:Longint);
FileOpen 開啓檔案。function FileOpen(const FileName: string; Mode:Word): Integer;
FileWrite 寫資料到檔案。function FileWrite(Handle:Integer;const Buffer; Count:Longint): Longint;
FindClose 終止找尋第一個/下一個的動作。procedure FindClose(var SearchRec: TSearchRec);
FindFirst 尋找第一個符合的檔案並設定其屬性。
function FindFirst(const Path: string;Attr: Word; var F:TSearchRec): Integer;
FindNext 傳回下一個符合的檔案。function FindNext(var F:TSearchRec): Integer;
RenameFile 變更檔名。function RenameFile(const OldName,NewName: string):Boolean;

怎樣在 CASE 語句中使用字符串
/////////////////////////////////////////

首先建立 CaseString 函數,用於獲取某字符串在一個字符串數組中的順序:

function CaseString (const s: string;
const x: array of string): Integer;
var i: Integer;
begin
Result:= -1; // Default return parameter
for i:= Low (x) to High (x) do begin
if s = x[i] then begin Result:= i; Exit; end;
end;
end;

Low() 提供第一個數組成員(通常是0),High() 則返回最後一個。因爲 CaseString 返回的是待查字符串在字符串數組中的位置,因此,它可以被直接用到 CASE 語句中:

search:= 'delphi3000';
case CaseString (search, ['delphi3000',
'delphipages',
'Torry's']) of
0: s:= 'Excellent!';
1: s:= 'Good source';
2: s:= 'Not bad!';
end;

copy(str,pos,num) 從str字符串的pos處開始,截取num個字符的串返回.假設str爲'abcdef',copy(str,3,2)='cd',copy(str,4,10)='def'
concat(str1,str2{,strn}) 把各自變量連接起來,返回連接後的字符串(長度不能超過255)

length(str) 返回str的字符個數,即其長度.

pos(obj,target) 在target字符串中找出第一個出現obj的第一個字符位置,如果找不到,返回0.

AnsiStrLastChar('你好')結果是“好”。如果有半個漢字出現,返回這半個漢字。二者字符串長度分別爲2和1。

CompareStr - 區分大小寫
CompareText - 不區分大小寫

////////////////////////////////////////////////////////
{判斷字符是否是數字}
function IsDigit(ch: char): boolean;
begin
Result := ch in ['0'..'9'];
end;
{判斷字符是否是大寫字符}
function IsUpper(ch: char): boolean;
begin
Result := ch in ['A'..'Z'];
end;

{判斷字符是否是小寫字符}
function IsLower(ch: char): boolean;
begin
Result := ch in ['a'..'z'];
end;

{轉換爲大寫字符}
function ToUpper(ch: char): char;
begin
Result := chr(ord(ch) and $DF);
end;

{轉換爲小寫字符}
function ToLower(ch: char): char;
begin
Result := chr(ord(ch) or $20);
end;

{ Capitalizes first letter of every word in s }
function Proper(const s: string): string;
var
i: Integer;
CapitalizeNextLetter: Boolean;
begin
Result := LowerCase(s);
CapitalizeNextLetter := True;
for i := 1 to Length(Result) do
begin
if CapitalizeNextLetter and IsLower(Result[i]) then
Result[i] := ToUpper(Result[i]);
CapitalizeNextLetter := Result[i] = ' ';
end;
end;
////////////////////////////////////////////////////////////
{返回兩個子字符串之間字符的個數}
Function p2pcount( s, ss1, ss2 : string ): integer;
var i, j, slen : integer;
begin
i := pos( ss1, s );
j := pos( ss2, s );
slen := Length(ss2);
if j >= i then Result := j - i + slen else Result := 0;
end;

{更快速的字符查詢,快40%}
function ScanStr(ToScan: PChar; Sign: Char):PChar;
begin
Result:= nil;
if ToScan <> nil then
while (ToScan^ <> #0) do begin
if ToScan^ = Sign then begin
Result:= ToScan;
break;
end;
inc(ToScan);
end;
end;
/////////////////////////////
替換字符串中子串的函數,他可以從字符串中找出指定子串,並替換爲另一子串。
function replacing(S,source,target:string):string;
var site,StrLen:integer;
begin
{source在S中出現的位置}
site:=pos(source,s);

{source的長度}
StrLen:=length(source);

{刪除source字符串}
delete(s,site,StrLen);

{插入target字符串到S中}
insert(target,s,site);

{返回新串}
replacing:=s;
end;
///////////////////////
另兩個替換字符串中子串的函數
function repl_substr( sub1, sub2, s: string ): string;
var i: integer;
begin
repeat
i := pos( sub1, s ) ;
if i > 0 then begin
delete( s, i, Length(sub1));
insert( sub2, s, i );
end;
until i < 1;
Result := s;
end;

function ReplaceText(const S,ReplacePiece,ReplaceWith: String):String;

Var Position: Integer;
TempStr: String;
begin
Position := Pos(ReplacePiece,S);
if Position > 0 then Begin
TempStr := S;
Delete(TempStr,1,Position-1+Length(ReplacePiece));
Result :=
Copy(S,1,Position-1)+ReplaceWith+ReplaceText(TempStr,ReplacePiece,ReplaceWith)

End else Result := S;
end;
////////////////////////
替換全部子字符串的函數

function ReplaceSub(str, sub1, sub2: String): String;
var
aPos: Integer;
rslt: String;

begin
aPos := Pos(sub1, str);
rslt := '';
while (aPos <> 0) do begin
rslt := rslt + Copy(str, 1, aPos - 1) + sub2;
Delete(str, 1, aPos + Length(sub1));
aPos := Pos(sub1, str);
end;
Result := rslt + str;
end;

/////////////////////////
在字符串左右填充指定數量的指定字符
function UT_PadString(inString :string; maxLength :integer; padChar :char;
left :boolean) :string;
begin
result := inString;
while (Length(result) < maxLength) do
if (left) then
result := padChar + result
else
result := result + padChar;
end;
/////////////////////////////////////
提取字符串中指定子字符串前的字符串
Function Before ( Src:string ; Var S:string ) : string ;
Var
F : Word ;

begin
F := POS (Src,S) ;
if F=0 then
Before := S
else
Before := COPY(S,1,F-1) ;
end ;
//////////////////////////////////
提取字符串中指定子字符串後的字符串
Function After ( Src:string ; Var S:string ) : string ;
Var
F : Word ;

begin
F := POS (Src,S) ;
if F=0 then
After := ''
else
After := COPY(S,F+length(src),length(s)) ;
end ;
////////////////////////////////////
判斷字符串是否可以轉換爲整數
function IsIntStr(const S: string): boolean;
begin
Result:=StrToIntDef(S,0)=StrToIntDef(S,1);
end;
//////////////////////////////////////
從字符串中刪除指定字符串
procedure RemoveInvalid(what, where: string): string;

var
tstr: string;

begin
tstr:=where;
while pos(what, tstr)>0 do
tstr:=copy(tstr,1,pos(what,tstr)-1) +
copy(tstr,pos(what,tstr)+length(tstr),length(tstr));
Result:=tstr;
end;
用法:
NewStr:=RemoveInvalid('<invalid>','This <invalid> is my string and I wan to
remove the word <invalid>');
///////////////////////////////////////////
根據某個字符分割字符串的函數
procedure SeparateTerms(s : string;Separator : char;Terms : TStringList);
{ This browses a string and divide it into terms whenever the given
separator is found. The separators will be removed }
var
hs : string;
p : integer;

begin
Terms.Clear; // First remove all remaining terms
if Length(s)=0 then // Nothin' to separate
Exit;
p:=Pos(Separator,s);
while P<>0 do
begin
hs:=Copy(s,1,p-1); // Copy term
Terms.Add(hs); // Add to list
Delete(s,1,p); // Remove term and separator
p:=Pos(Separator,s); // Search next separator
end;
if Length(s)>0 then
Terms.Add(s); // Add remaining term
end;
==========
= 用 法
==========

var
Terms : TStringList;
i : integer;

const
TestStr = '1st term;2nd term;3rd term';

begin
Terms:=TStringList.Create;
SeparateTerms(TestStr,';',Terms);
for i:=0 to terms.Count-1 do
ShowMessage(Terms.Strings[i]);
Terms.Free;
end;
/////////////////////////////
根據一組字符分割字符串的函數
type
Charset = set of Char;
var
f : Text;
s : String;

procedure WriteStringSplitted(var s: String; Separators: Charset);
var
a,e : Integer; {anfang und ende des w鰎tchens}
begin
a := 1;
for e := 1 to Length(s) do
if s[e] in Separators then begin
WriteLn(Copy(s, a, e-a));
a := e + 1;
end;
WriteLn(Copy(s, a, e-a+1));
end;

begin
Assign(f, 'c:/dingsbums/text.txt');
Reset(f);
while not EOF(f) do begin
ReadLn(f,s);
WriteStringSplitted(s, [':', ',']);
end;
Close(f);
end.
//////////////////////////////////////////////////

{===============================================================}
{ 函數 : RESULTSTRING = HexToBin(HEXSTRING)
{ 目的 : 把十六進制字符串轉換爲二進制字符串
{
{===============================================================}
{ 函數 : RESULTINTEGER = HexCharToInt(HEXCHAR)
{ 目的 : 轉換一個十六進制字符爲整數
{===============================================================}
{ 函數 : RESULTSTRING = HexCharToBin(HEXCHAR)
{ 目的 : 轉換一個十六進制字符爲二進制字符串
{===============================================================}
{ 函數 : RESULTINTEGER = Pow(BASE,POWER)
{ 目的 : 指數函數
{===============================================================}
{ 函數 : RESULTINTEGER = BinStrToInt(BINSTRING)
{ 目的 : 把二進制字符串轉換爲整數
{===============================================================}
{ 函數 : RESULTSTRING = DecodeSMS7Bit (PDUSTRING)
{ 目的 : 解碼一個7-bit SMS (GSM 03.38) 爲ASCII碼
{===============================================================}
{ 函數 : RESULTSTRING = ReverseStr (SOURCESTRING)
{ 目的 : 反轉一個字符串
{===============================================================}

unit BinHexTools;
interface

function HexToBin(HexNr : string): string;
function HexCharToInt(HexToken : char):Integer;
function HexCharToBin(HexToken : char): string;
function pow(base, power: integer): integer;
function BinStrToInt(BinStr : string) : integer;
function DecodeSMS7Bit(PDU : string):string;
function ReverseStr(SourceStr : string) : string;

implementation

uses sysutils, dialogs;

function HexCharToInt(HexToken : char):Integer;
begin
{if HexToken>#97 then HexToken:=Chr(Ord(HexToken)-32);
{ use lowercase aswell }

Result:=0;

if (HexToken>#47) and (HexToken<#58) then { chars 0....9 }
Result:=Ord(HexToken)-48
else if (HexToken>#64) and (HexToken<#71) then { chars A....F }
Result:=Ord(HexToken)-65 + 10;
end;

function HexCharToBin(HexToken : char): string;
var DivLeft : integer;
begin
DivLeft:=HexCharToInt(HexToken); { first HEX->BIN }
Result:='';
{ Use reverse dividing }
repeat { Trick; divide by 2 }
if odd(DivLeft) then { result = odd ? then bit = 1 }
Result:='1'+Result { result = even ? then bit = 0 }
else
Result:='0'+Result;

DivLeft:=DivLeft div 2; { keep dividing till 0 left and length = 4 }
until (DivLeft=0) and (length(Result)=4); { 1 token = nibble = 4 bits }
end;

function HexToBin(HexNr : string): string;
{ only stringsize is limit of binnr }
var Counter : integer;
begin
Result:='';

for Counter:=1 to length(HexNr) do
Result:=Result+HexCharToBin(HexNr[Counter]);
end;

function pow(base, power: integer): integer;
var counter : integer;
begin
Result:=1;

for counter:=1 to power do
Result:=Result*base;
end;

function BinStrToInt(BinStr : string) : integer;
var counter : integer;
begin
if length(BinStr)>16 then
raise ERangeError.Create(#13+BinStr+#13+
'is not within the valid range of a 16 bit binary.'+#13);

Result:=0;

for counter:=1 to length(BinStr) do
if BinStr[Counter]='1' then
Result:=Result+pow(2,length(BinStr)-counter);
end;

function DecodeSMS7Bit(PDU : string):string;
var OctetStr : string;
OctetBin : string;
Charbin : string;
PrevOctet: string;
Counter : integer;
Counter2 : integer;
begin
PrevOctet:='';
Result:='';

for Counter:=1 to length(PDU) do
begin
if length(PrevOctet)>=7 then { if 7 Bit overflow on previous }
begin
if BinStrToInt(PrevOctet)<>0 then
Result:=Result+Chr(BinStrToInt(PrevOctet))
else Result:=Result+' ';

PrevOctet:='';
end;

if Odd(Counter) then { only take two nibbles at a time }
begin
OctetStr:=Copy(PDU,Counter,2);
OctetBin:=HexToBin(OctetStr);

Charbin:='';
for Counter2:=1 to length(PrevOctet) do
Charbin:=Charbin+PrevOctet[Counter2];

for Counter2:=1 to 7-length(PrevOctet) do
Charbin:=OctetBin[8-Counter2+1]+Charbin;

if BinStrToInt(Charbin)<>0 then Result:=Result+Chr(BinStrToInt(CharBin))
else Result:=Result+' ';

PrevOctet:=Copy(OctetBin,1,length(PrevOctet)+1);
end;
end;
end;

function ReverseStr(SourceStr : string) : string;
var Counter : integer;
begin
Result:='';

for Counter:=1 to length(SourceStr) do
Result:=SourceStr[Counter]+Result;
end;

end.
在Delphi中沒有前導0輸出的函數,如C語言中printf("%08d",10);就會輸"000000010",但是在實際應用中經常會用到此種函數,如財務等數據的輸出。如何實現?以下的代碼實現了這種功能,

function qd0str(const count,num:integer):String;
Var
s1,s2:String;
begin
s1:=IntToStr(Num);
s2:='00000000000000000000';
if (Length(s1)>=count) then
s2:=''
else if(count>20) then
SetLength(S2,20-Length(s1))
else
SetLength(S2,count-Length(s1));

Result:=S2+S1;
end;

函數的參數count爲輸出字符串的總長度,在函數中定義爲最大20。Num爲需要轉換成字符串的數據。
////////////////////////////////////////
function IntToLZStr(value : integer;digits : byte) : string;
var
Res : string;

begin
Res:=IntToStr(value);
while Length(Res)<digits do
Insert('0',res,1);
IntToLZStr:=Res;
end;

函數 function AnsiResemblesText(const AText, AOther: string): Boolean; $[StrUtils.pas
功能 返回兩個字符串是否相似
說明 ANSI(American National Standards Institute)美國國家標準協會;不區分大小寫
參考 function StrUtils.SoundexProc; var StrUtils.AnsiResemblesProc
例子 CheckBox1.Checked := AnsiResemblesText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiContainsText(const AText, ASubText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否包含子串ASubText
說明 不區分大小寫
參考 function StrUtils.AnsiUppercase; function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStartsText(const ASubText, AText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否以子串ASubText開頭
說明 不區分大小寫
參考 function Windows.CompareString
例子 CheckBox1.Checked := AnsiStartsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiEndsText(const ASubText, AText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否以子串ASubText結尾
說明 不區分大小寫
參考 function Windows.CompareString
例子 CheckBox1.Checked := AnsiEndsText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiReplaceText(const AText, AFromText, AToText: string): string; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替換成子串AToText的結果
說明 不區分大小寫
參考 function SysUtils.StringReplace; type SysUtils.TReplaceFlags
例子 Edit4.Text := AnsiReplaceText(Edit1.Text, Edit2.Text, Edit3.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiMatchText(const AText: string; const AValues: array of string): Boolean; $[StrUtils.pas
功能 返回字符串數組AValues中是否包含字符串AText
說明 不區分大小寫
參考 function StrUtils.AnsiIndexText
例子 CheckBox1.Checked := AnsiMatchText(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiIndexText(const AText: string; const AValues: array of string): Integer; $[StrUtils.pas
功能 返回字符串AText在字符串數組AValues中的位置
說明 不區分大小寫;如果不包含則返回-1
參考 function SysUtils.AnsiSameText
例子 SpinEdit1.Value := AnsiIndexText(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiContainsStr(const AText, ASubText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否包含子串ASubText
說明 區分大小寫
參考 function StrUtils.AnsiPos
例子 CheckBox1.Checked := AnsiContainsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStartsStr(const ASubText, AText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否以子串ASubText開頭
說明 區分大小寫
參考 function SysUtils.AnsiSameStr
例子 CheckBox1.Checked := AnsiStartsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiEndsStr(const ASubText, AText: string): Boolean; $[StrUtils.pas
功能 返回字符串AText是否以子串ASubText結尾
說明 區分大小寫
參考 function SysUtils.AnsiSameStr
例子 CheckBox1.Checked := AnsiEndsStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiReplaceStr(const AText, AFromText, AToText: string): string; $[StrUtils.pas
功能 返回字符串AText中用子串AFromText替換成子串AToText的結果
說明 區分大小寫
參考 function SysUtils.StringReplace; type SysUtils.TReplaceFlags
例子 Edit4.Text := AnsiReplaceStr(Edit1.Text, Edit2.Text, Edit3.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiMatchStr(const AText: string; const AValues: array of string): Boolean; $[StrUtils.pas
功能 返回字符串數組AValues中是否包含字符串AText
說明 區分大小寫
參考 function StrUtils.AnsiIndexStr
例子 CheckBox1.Checked := AnsiMatchStr(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiIndexStr(const AText: string; const AValues: array of string): Integer; $[StrUtils.pas
功能 返回字符串AText在字符串數組AValues中的位置
說明 區分大小寫
參考 function SysUtils.AnsiSameStr
例子 SpinEdit1.Value := AnsiIndexStr(Edit1.Text, ['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function DupeString(const AText: string; ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText的ACount個複本
說明 當ACount爲0時返回''
參考 function System.SetLength
例子 Edit3.Text := DupeString(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function ReverseString(const AText: string): string; $[StrUtils.pas
功能 返回字符串AText的反序
說明 ReverseString('1234') = '4321'
參考 function System.SetLength
例子 Edit3.Text := ReverseString(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StuffString(const AText: string; AStart, ALength: Cardinal; const ASubText: string): string; $[StrUtils.pas
功能 返回嵌套字符串
說明 AStart:嵌套開始位置;ALength:嵌套長度;StuffString('abcd', 2, 0, '12') = 'a12bcd'
參考 function System.Copy
例子 Edit3.Text := StuffString(Edit1.Text, SpinEdit1.Value, SpinEdit2.Value, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function RandomFrom(const AValues: array of string): string; overload; $[StrUtils.pas
功能 隨機返回字符串數組AValues中的一個元素
說明 之前建議執行Randomize
參考 function System.Random
例子 Randomize; Edit3.Text := RandomFrom(['a1', 'a2', 'a3', 'a4']);
━━━━━━━━━━━━━━━━━━━━━
函數 function IfThen(AValue: Boolean; const ATrue: string; AFalse: string = ''): string; overload; $[StrUtils.pas
功能 返回指定的邏輯字符串
說明 IfThen(True, '是', '否') = '是';IfThen(False, '是', '否') = '否'
參考 <NULL>
例子 Edit3.Text := IfThen(CheckBox1.Checked, Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function LeftStr(const AText: string; const ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText左邊的ACount個字符
說明 LeftStr('123456', 3) = '123'
參考 function System.Copy
例子 Edit3.Text := LeftStr(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function RightStr(const AText: string; const ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText右邊的ACount個字符
說明 RightStr('123456', 3) = '456'
參考 function System.Copy
例子 Edit3.Text := RightStr(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function MidStr(const AText: string; const AStart, ACount: Integer): string; $[StrUtils.pas
功能 返回字符串AText從AStart開始的ACount個字符
說明 其實就是Copy
參考 function System.Copy
例子 Edit3.Text := MidStr(Edit1.Text, SpinEdit1.Value, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SearchBuf(Buf: PChar; BufLen: Integer; SelStart, SelLength: Integer; SearchString: String; Options: TStringSearchOptions = [soDown]): PChar; $[StrUtils.pas
功能 返回第一個搜索到的指針位置
說明 這函數常用於文本中搜索字符串
參考 <NULL>
例子
///////Begin SearchBuf
function SearchEdit(EditControl: TCustomEdit; const SearchString: String;
SearchOptions: TStringSearchOptions; FindFirst: Boolean = False): Boolean;
var
Buffer, P: PChar;
Size: Word;
begin
Result := False;
if (Length(SearchString) = 0) then Exit;
Size := EditControl.GetTextLen;
if (Size = 0) then Exit;
Buffer := StrAlloc(Size + 1);
try
EditControl.GetTextBuf(Buffer, Size + 1);
P := SearchBuf(Buffer, Size, EditControl.SelStart, EditControl.SelLength,
SearchString, SearchOptions);
if P <> nil then begin
EditControl.SelStart := P - Buffer;
EditControl.SelLength := Length(SearchString);
Result := True;
end;
finally
StrDispose(Buffer);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
SearchOptions: TStringSearchOptions;
begin
SearchOptions := [];
if CheckBox1.Checked then
Include(SearchOptions, soDown);
if CheckBox2.Checked then
Include(SearchOptions, soMatchCase);
if CheckBox3.Checked then
Include(SearchOptions, soWholeWord);
SearchEdit(Memo1, Edit1.Text, SearchOptions);
Memo1.SetFocus;
end;
///////End SearchBuf
━━━━━━━━━━━━━━━━━━━━━
函數 function Soundex(const AText: string; ALength: TSoundexLength = 4): string; $[StrUtils.pas
功能 返回探測字符串
說明 根據探測法(Soundex)可以找到相進的字符串;http://www.nara.gov/genealogy/coding.html
參考 <NULL>
例子 Edit2.Text := Soundex(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexInt(const AText: string; ALength: TSoundexIntLength = 4): Integer; $[StrUtils.pas
功能 返回探測整數
說明 ALength的值越大解碼準確率越高
參考 <NULL>
例子 SpinEdit2.Value := SoundexInt(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function DecodeSoundexInt(AValue: Integer): string; $[StrUtils.pas
功能 返回探測整數的解碼
說明 DecodeSoundexInt(SoundexInt('hello')) 相當於 Soundex('hello')
參考 <NULL>
例子 Edit2.Text := DecodeSoundexInt(SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexWord(const AText: string): Word; $[StrUtils.pas
功能 返回探測文字數值
說明 沒有參數ALength已經固定爲4
參考 <NULL>
例子 SpinEdit2.Value := SoundexWord(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function DecodeSoundexWord(AValue: Word): string; $[StrUtils.pas
功能 返回探測文字數值的解碼
說明 DecodeSoundexWord(SoundexWord('hello')) 相當於 Soundex('hello')
參考 <NULL>
例子 Edit2.Text := DecodeSoundexWord(SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexSimilar(const AText, AOther: string; ALength: TSoundexLength = 4): Boolean; $[StrUtils.pas
功能 返回兩個字符串的探測字符串是否相同
說明 Result := Soundex(AText, ALength) = Soundex(AOther, ALength)
參考 <NULL>
例子 CheckBox1.Checked := SoundexSimilar(Edit1.Text, Edit2.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexCompare(const AText, AOther: string; ALength: TSoundexLength = 4): Integer; $[StrUtils.pas
功能 返回比較兩個字符串的探測字符串的結果
說明 Result := AnsiCompareStr(Soundex(AText, ALength), Soundex(AOther, ALength))
參考 function SysUtils.AnsiCompareStr
例子 SpinEdit2.Value := SoundexCompare(Edit1.Text, Edit2.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function SoundexProc(const AText, AOther: string): Boolean; $[StrUtils.pas
功能 調用SoundexSimilar返回兩個字符串的探測字符串是否相同
說明 系統變量AnsiResemblesProc的默認值
參考 function StrUtils.AnsiResemblesText
例子 [var AnsiResemblesProc: TCompareTextProc = SoundexProc;]
━━━━━━━━━━━━━━━━━━━━━
函數 function NewStr(const S: string): PString; deprecated; $[SysUtils.pas
功能 返回一個新的字符串指針地址
說明 字符串S爲空時返回NullStr
參考 procedure System.New
例子
////////Begin NewStr,DisposeStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PString;
begin
P := NewStr(Edit1.Text);
Edit2.Text := P^;
DisposeStr(P);
end;
////////End NewStr,DisposeStr
━━━━━━━━━━━━━━━━━━━━━
函數 procedure DisposeStr(P: PString); deprecated; $[SysUtils.pas
功能 釋放字符串指針P資源
說明 配合函數NewStr使用
參考 procedure System.Dispose
例子 <如上參見,如下參見>
━━━━━━━━━━━━━━━━━━━━━
函數 procedure AssignStr(var P: PString; const S: string); deprecated; $[SysUtils.pas
功能 將字符串S更新給字符串指針P
說明 更新值時會釋放以前字符串指針的資源
參考 function SysUtils.NewStr;function SysUtils.DisposeStr
例子
////////Begin AssignStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PString;
begin
P := nil;
AssignStr(P, Edit1.Text);
Edit2.Text := P^;
DisposeStr(P);
end;
////////End AssignStr
━━━━━━━━━━━━━━━━━━━━━
函數 procedure AppendStr(var Dest: string; const S: string); deprecated; $[SysUtils.pas
功能 在字符串Dest後追加字符串S
說明 相當於Dest := Dest + S;Delphi6已經不建議使用
參考 <NULL>
例子
////////Begin AppendStr
procedure TForm1.Button1Click(Sender: TObject);
var
S: string;
begin
S := Edit2.Text;
AppendStr(S, Edit1.Text);
Edit2.Text := S;
end;
////////End AppendStr
━━━━━━━━━━━━━━━━━━━━━
函數 function UpperCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的大寫形式
說明 非小寫字符不處理
參考 procedure System.SetLength
例子 Edit2.Text := UpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function LowerCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的小寫形式
說明 非大寫字符不處理
參考 procedure System.SetLength
例子 Edit2.Text := LowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function CompareStr(const S1, S2: string): Integer; $[SysUtils.pas
功能 返回比較兩個字符
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 <NULL>
例子 SpinEdit1.Value := CompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function CompareMem(P1, P2: Pointer; Length: Integer): Boolean; assembler; $[SysUtils.pas
功能 返回比較兩個內存指針
說明 CompareMem(PChar('12a'), PChar('12c'), 2)=True;CompareMem(PChar('12a'), PChar('12c'), 3)=False
參考 <NULL>
例子 CheckBox1.Checked := CompareMem(Self, Form1, 8);
━━━━━━━━━━━━━━━━━━━━━
函數 function CompareText(const S1, S2: string): Integer; $[SysUtils.pas
功能 返回比較兩個字符串
說明 不區分大小寫
參考 <NULL>
例子 SpinEdit1.Value := CompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function SameText(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個字符串是否相等
說明 不區分大小寫
參考 <NULL>
例子 CheckBox1.Checked := SameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiUpperCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的大寫形式
說明 ANSI(American National Standards Institute)美國國家標準協會;非小寫的字符不變
參考 function Windows.CharUpperBuff
例子 Edit2.Text := AnsiUpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiLowerCase(const S: string): string; $[SysUtils.pas
功能 返回字符串S的小寫形式
說明 非大寫字符不處理
參考 function Windows.CharLowerBuff
例子 Edit2.Text := AnsiLowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiCompareStr(const S1, S2: string): Integer; $[SysUtils.pas
功能 反回比較兩個字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiCompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiSameStr(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個字符串是否相等
說明 區分大小寫
參考 function SysUtils.AnsiCompareStr
例子 CheckBox1.Checked := AnsiSameStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiCompareText(const S1, S2: string): Integer; $[SysUtils.pas
功能 反回比較兩個字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiCompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiSameText(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個字符串是否相等
說明 不區分大小寫
參考 function SysUtils.AnsiCompareText
例子 CheckBox1.Checked := AnsiSameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrComp(S1, S2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 function System.CompareString
例子 SpinEdit1.Value := AnsiStrComp(PChar(Edit1.Text), PChar(Edit2.Text))
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrIComp(S1, S2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫;Ignore(忽略)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrIComp(PChar(Edit1.Text), PChar(Edit2.Text))
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrLComp(S1, S2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串指定長度
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫;Length(長度)
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrLComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrLIComp(S1, S2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串指定長度
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫
參考 function Windows.CompareString
例子 SpinEdit1.Value := AnsiStrLIComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrLower(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串小寫形式
說明 非大寫字符不處理
參考 function Windows.CharLower
例子 Edit2.Text := AnsiStrLower(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrUpper(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串大寫形式
說明 非小寫字符不處理
參考 function Windows.CharUpper
例子 Edit2.Text := AnsiStrUpper(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiLastChar(const S: string): PChar; $[SysUtils.pas
功能 返回字符串S的最後一個指針字符
說明 當字符串S爲空串則返回空指針
參考 function SysUtils.ByteType
例子 Edit2.Text := AnsiLastChar(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrLastChar(P: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串P的最後一個指針字符
說明 當字符串P爲空空指針則返回空指針
參考 function SysUtils.ByteType
例子 Edit2.Text := AnsiLastChar(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function WideUpperCase(const S: WideString): WideString; $[SysUtils.pas
功能 返回雙字節字符串的大寫形式
說明 WideChar雙字節字符
參考 function Windows.CharUpperBuffW
例子 Edit2.Text := WideUpperCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideLowerCase(const S: WideString): WideString; $[SysUtils.pas
功能 返回雙字節字符串的小寫形式
說明 我怎麼就測試不出來呢
參考 function Windows.CharLowerBuffW
例子 Edit2.Text := WideLowerCase(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideCompareStr(const S1, S2: WideString): Integer; $[SysUtils.pas
功能 返回比較兩個雙字節字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 function Windows.CompareStringW
例子 SpinEdit1.Value := WideCompareStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideSameStr(const S1, S2: WideString): Boolean; $[SysUtils.pas
功能 返回兩個雙字節字符串是否相同
說明 區分大小寫
參考 function SysUtils.WideCompareStr
例子 CheckBox1.Checked := WideSameStr(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideCompareText(const S1, S2: WideString): Integer; $[SysUtils.pas
功能 返回比較兩個雙字節字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫
參考 function Windows.CompareStringW
例子 SpinEdit1.Value := WideCompareText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function WideSameText(const S1, S2: WideString): Boolean; $[SysUtils.pas
功能 返回兩個雙字節字符串是否相同
說明 不區分大小寫
參考 function SysUtils.WideCompareText
例子 CheckBox1.Checked := WideSameText(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function Trim(const S: string): string; overload; $[SysUtils.pas
函數 function Trim(const S: WideString): WideString; overload; $[SysUtils.pas
功能 返回除去字符串S左右不可見字符
說明 小於#32的字符看作不可見字符
參考 function System.Copy
例子 Edit2.Text := Trim(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function TrimLeft(const S: string): string; overload; $[SysUtils.pas
函數 function TrimLeft(const S: WideString): WideString; overload; $[SysUtils.pas
功能 返回除去字符串S左邊不可見字符
說明 小於#32的字符看作不可見字符
參考 function System.Copy
例子 Edit2.Text := TrimLeft(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function TrimRight(const S: string): string; overload; $[SysUtils.pas
函數 function TrimRight(const S: WideString): WideString; overload; $[SysUtils.pas
功能 返回除去字符串S右邊不可見字符
說明 小於#32的字符看作不可見字符
參考 function System.Copy
例子 Edit2.Text := TrimRight(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function QuotedStr(const S: string): string; $[SysUtils.pas
功能 返回字符串S在pascal中的表現形式
說明 單引號中的一個單引號將轉成兩個
參考 procedure System.Insert
例子 Edit2.Text := QuotedStr(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiQuotedStr(const S: string; Quote: Char): string; $[SysUtils.pas
功能 返回字符串S以字符Quote爲引號的表現形式
說明 AnsiQuotedStr('hello"world', '@')='@hello"world@';AnsiQuotedStr('hello"world', '"')='"hello""world"'
參考 function SysUtils.AnsiStrScan
例子 Edit2.Text := AnsiQuotedStr(Edit1.Text, '"');
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string; $[SysUtils.pas
功能 返回以字符Quote爲引號的表現形式原形
說明 表現形式非法時Src不變否則爲空
參考 function SysUtils.AnsiStrScan
例子
///////Begin AnsiExtractQuotedStr
procedure TForm1.Button1Click(Sender: TObject);
var
P: PChar;
begin
P := PChar(Edit1.Text);
Edit2.Text := AnsiExtractQuotedStr(P, '"');
Edit3.Text := P;
end;
///////End AnsiExtractQuotedStr
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiDequotedStr(const S: string; AQuote: Char): string; $[SysUtils.pas
功能 返回以字符AQuote爲引號的表現形式原形
說明 表現形式非法時則返回S
參考 function SysUtils.AnsiExtractQuotedStr
例子 Edit2.Text := AnsiDequotedStr(Edit1.Text, '"');
━━━━━━━━━━━━━━━━━━━━━
函數 function AdjustLineBreaks(const S: string; Style: TTextLineBreakStyle = {$IFDEF LINUX} tlbsLF {$ENDIF} {$IFDEF MSWINDOWS} tlbsCRLF {$ENDIF}): string; $[SysUtils.pas
功能 返回將給定字符串的行分隔符調整爲CR/LF序列
說明 AdjustLineBreaks('1'#13'2'#13)='1'#13#10'2'#13#10;AdjustLineBreaks('1'#10'2'#10)='1'#13#10'2'#13#10
參考 function SysUtils.StrNextChar
例子 <NULL>
━━━━━━━━━━━━━━━━━━━━━
函數 function IsValidIdent(const Ident: string): Boolean; $[SysUtils.pas
功能 返回字符串Ident是否是正確的標識符
說明 標識符::字母|下劃線[字母|下劃線|數字]...
參考 <NULL>
例子 CheckBox1.Checked := IsValidIdent(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function IntToStr(Value: Integer): string; overload; $[SysUtils.pas
函數 function IntToStr(Value: Int64): string; overload; $[SysUtils.pas
功能 返回整數Value轉換成字符串
說明 Format('%d', [Value])
參考 function SysUtils.FmtStr
例子 Edit2.Text := IntToStr(SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function IntToHex(Value: Integer; Digits: Integer): string; overload; $[SysUtils.pas
函數 function IntToHex(Value: Int64; Digits: Integer): string; overload; $[SysUtils.pas
功能 返回整數Value轉換成十六進制表現結果;Format('%.*x', [Digits, Value])
說明 參數Digits指定字符最小寬度;最小寬度不足時將用0填充
參考 function SysUtils.FmtStr
例子 Edit2.Text := IntToHex(SpinEdit1.Value, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToInt(const S: string): Integer; $[SysUtils.pas
功能 返回字符串S轉換成整數
說明 字符串非整數表達時將引起異常
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToIntDef(const S: string; Default: Integer): Integer; $[SysUtils.pas
功能 返回字符串S轉換成整數
說明 字符串非整數表達時則返回默認值Default
參考 procedure System.Val
例子 SpinEdit1.Value := StrToIntDef(Edit1.Text, 0);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToInt(const S: string; out Value: Integer): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成整數Value是否成功
說明 字符串非整數表達時返回False並且Value將輸出爲0
參考 procedure System.Val
例子
///////Begin TryStrToInt
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
CheckBox1.Checked := TryStrToInt(Edit1.Text, I);
SpinEdit1.Value := I;
end;
///////End TryStrToInt
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToInt64(const S: string): Int64; $[SysUtils.pas
功能 返回字符串S轉換成六十四位整數
說明 字符串非六十四位整數表達時將引起異常
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt64(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToInt64Def(const S: string; const Default: Int64): Int64; $[SysUtils.pas
功能 返回字符串S轉換成六十四位整數
說明 字符串非六十四位整數表達時則返回默認值Default
參考 procedure System.Val
例子 SpinEdit1.Value := StrToInt64Def(Edit1.Text, 0);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToInt64(const S: string; out Value: Int64): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成六十四位整數Value是否成功
說明 字符串非六十四位整數表達時返回False並且Value將輸出爲0
參考 procedure System.Val
例子
///////Begin TryStrToInt64
procedure TForm1.Button1Click(Sender: TObject);
var
I: Int64;
begin
CheckBox1.Checked := TryStrToInt64(Edit1.Text, I);
SpinEdit1.Value := I;
end;
///////End TryStrToInt64
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToBool(const S: string): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成邏輯值
說明 字符非邏輯表達時將引起異常
參考 function SysUtils.TryStrToBool
例子 CheckBox1.Checked := StrToBool(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToBoolDef(const S: string; const Default: Boolean): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成邏輯值
說明 字符非邏輯表達時則返回默認值Default
參考 function SysUtils.TryStrToBool
例子 CheckBox1.Checked := StrToBoolDef(Edit1.Text, False);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToBool(const S: string; out Value: Boolean): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成邏輯值Value是否成功
說明 [注意]0爲假非0爲真;不是'True'和'False';Delphi6 Bug 如下修正
參考 function SysUtils.AnsiSameText;var SysUtils.TrueBoolStrs;var SysUtils.FalseBoolStrs
例子
///////Begin TryStrToBool
procedure TForm1.Button1Click(Sender: TObject);
var
B: Boolean;
begin
SetLength(TrueBoolStrs, 2);
SetLength(FalseBoolStrs, 2);
TrueBoolStrs[0] := 'True';
FalseBoolStrs[0] := 'False';
TrueBoolStrs[1] := 'Yes';
FalseBoolStrs[1] := 'No';
CheckBox1.Checked := TryStrToBool(Edit1.Text, B);
CheckBox2.Checked := B;
end;
///////End TryStrToBool
附加
///////Begin TryStrToBool
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
function CompareWith(const aArray: array of string): Boolean;
var
I: Integer;
begin
Result := False;
for I := Low(aArray) to High(aArray) do
if AnsiSameText(S, aArray[I]) then
begin
Result := True;
Break;
end;
end;
var
LResult: Extended;
begin
Result := TryStrToFloat(S, LResult);
if Result then
Value := LResult <> 0
else
begin
Result := True; //修正處
VerifyBoolStrArray;
if CompareWith(TrueBoolStrs) then
Value := True
else if CompareWith(FalseBoolStrs) then
Value := False
else
Result := False;
end;
end;
///////End TryStrToBool
━━━━━━━━━━━━━━━━━━━━━
函數 function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string; $[SysUtils.pas
功能 返回邏輯值B轉換成字符串
說明 BoolToStr(False, False)='0';BoolToStr(False, True)='-1'
參考 var SysUtils.TrueBoolStrs;var SysUtils.FalseBoolStrs
例子 Edit1.Text := BoolToStr(CheckBox1.Checked, CheckBox2.Checked);
━━━━━━━━━━━━━━━━━━━━━
函數 function LoadStr(Ident: Integer): string; $[SysUtils.pas
功能 返回根據標識Ident的字符串資源
說明 字符串資源是指程序的內部資源
參考 function SysUtils.FindStringResource
例子 Edit2.Text := LoadStr(StrToIntDef(Edit1.Text, 0));
━━━━━━━━━━━━━━━━━━━━━
函數 function FmtLoadStr(Ident: Integer; const Args: array of const): string; $[SysUtils.pas
功能 返回格式化的字符串資源
說明 字符串資源是指程序的內部資源
參考 function SysUtils.FmtStr;function SysUtils.FindStringResource
例子 <NULL>;
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLen(const Str: PChar): Cardinal; $[SysUtils.pas
功能 返回指針字符串的長度
說明 當指針字符串Str爲nil時將觸發異常
參考 <NULL>
例子 SpinEdit2.Value := StrLen(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrEnd(const Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串的結尾
說明 當指針字符串Str爲nil時將觸發異常
參考 <NULL>
例子 Edit2.Text := StrEnd(PChar(Edit1.Text)) - SpinEdit1.Value;
━━━━━━━━━━━━━━━━━━━━━
函數 function StrMove(Dest: PChar; const Source: PChar; Count: Cardinal): PChar; $[SysUtils.pas
功能 返回將指針字符串Source指定內存數量Count複製覆蓋到指針字符串Dest中
說明 Dest沒有分配資源將觸發異常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複製到指針字符串Dest中
說明 Dest應已經分配足夠的空間非則將觸發異常
參考 <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複製到指針字符串Dest中的結尾
說明 可以連接指針字符串
參考 <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指定長度MaxLen複製到指針字符串Dest中
說明 Dest應已經分配足夠的空間非則將觸發異常
參考 <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複製到指針字符串Dest中
說明 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指定長度MaxLen複製到指針字符串Dest中
說明 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
說明 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
說明 [注意]MaxLen指定連接後的最大長度不是指針字符串Source的長度
參考 <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
功能 返回比較兩個指針字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫;[注意]返回第一個出現不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrComp(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrIComp(const Str1, Str2: PChar): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫;[注意]返回第一個出現不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrIComp(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串指定長度
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫;Length(長度);[注意]返回第一個出現不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrLComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLIComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer; $[SysUtils.pas
功能 返回比較兩個指針字符串指定長度
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;不區分大小寫;[注意]返回第一個出現不同字符的差異
參考 <NULL>
例子 SpinEdit1.Value := StrLIComp(PChar(Edit1.Text), PChar(Edit2.Text), SpinEdit2.Value)
━━━━━━━━━━━━━━━━━━━━━
函數 function StrScan(const Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr第一個出現的地址
說明 沒有找到則返回空指針
參考 <NULL>
例子 Edit2.Text := StrScan(PChar(Edit1.Text), '*');
━━━━━━━━━━━━━━━━━━━━━
函數 function StrRScan(const Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr最後一個出現的地址
說明 沒有找到則返回空指針
參考 <NULL>
例子 Edit2.Text := StrRScan(PChar(Edit1.Text), '*');
━━━━━━━━━━━━━━━━━━━━━
函數 function StrPos(const Str1, Str2: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串Str2在Str1中第一個出現的地址
說明 沒有找到則返回空指針;StrPos('12345', '3') = '345'
參考 <NULL>
例子 Edit3.Text := StrPos(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrUpper(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串Str大寫
說明 非小寫字符不處理
參考 <NULL>
例子 Edit1.Text := StrUpper(PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLower(Str: PChar): PChar; $[SysUtils.pas
功能 返回指針字符串Str小寫
說明 非大寫字符不處理
參考 <NULL>
例子 Edit1.Text := StrLower(PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrPas(const Str: PChar): string; $[SysUtils.pas
功能 返回指針字符串Str轉換成字符串
說明 也可以直接賦值
參考 <NULL>
例子 Edit1.Text := StrPas(PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrAlloc(Size: Cardinal): PChar; $[SysUtils.pas
功能 返回分配指定空間的內存資源給指針字符串
說明 空間的大小也將保存;用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
功能 返回通過函數StrAlloc分配的緩衝區大小
說明 出現異常情況則返回不可預知的結果
參考 function System.SizeOf
例子 SpinEdit1.Value := StrBufSize(StrAlloc(SpinEdit2.Value));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrNew(const Str: PChar): PChar; $[SysUtils.pas
功能 返回複製一個新的指針字符串
說明 如果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內存資源
說明 如果Str爲nil則不作任何處理;並且釋放空間大小信息
參考 function System.Dec;function System.SizeOf;function System.FreeMem
例子 <參見StrNew>
━━━━━━━━━━━━━━━━━━━━━
函數 function Format(const Format: string; const Args: array of const): string; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量的字符形式
說明 這個函數是我在Delphi中用得最多的函數,現在就列舉幾個例子給你個直觀的理解
"%" [索引 ":"] ["-"] [寬度] ["." 摘要] 類型
Format('x=%d', [12]); //'x=12' //最普通
Format('x=%3d', [12]); //'x= 12' //指定寬度
Format('x=%f', [12.0]); //'x=12.00' //浮點數
Format('x=%.3f', [12.0]); //'x=12.000' //指定小數
Format('x=%.*f', [5, 12.0]); //'x=12.00000' //動態配置
Format('x=%.5d', [12]); //'x=00012' //前面補充0
Format('x=%.5x', [12]); //'x=0000C' //十六進制
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' //科學記數法
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
功能 按指定方式格式化一個數組常量的字符形式返回
說明 <參見Format>
參考 function SysUtils.FormatBuf;function System.Length;function System.SetLength
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量的字符指針形式
說明 如果Buffer和Format其中只要有一個爲nil則返回nil
參考 function SysUtils.FormatBuf
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function StrLFmt(Buffer: PChar; MaxBufLen: Cardinal; Format: PChar; const Args: array of const): PChar; $[SysUtils.pas
功能 返回按指定方式和長度格式化一個數組常量的字符指針形式
說明 StrLFmt(vBuffer, 6, '%d|12345', [1024]) = '1024|1';
參考 function SysUtils.FormatBuf
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function FormatBuf(var Buffer; BufLen: Cardinal; const Format; FmtLen: Cardinal; const Args: array of const): Cardinal; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量到緩衝區Buffer中
說明 <NULL>
參考 <NULL>
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function WideFormat(const Format: WideString; const Args: array of const): WideString; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量的多字節字符形式
說明 <NULL>
參考 procedure SysUtils.WideFmtStr
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 procedure WideFmtStr(var Result: WideString; const Format: WideString; const Args: array of const); $[SysUtils.pas
功能 按指定方式格式化一個數組常量的多字節字符形式返回
說明 <NULL>
參考 function SysUtils.WideFormatBuf
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function WideFormatBuf(var Buffer; BufLen: Cardinal; const Format; FmtLen: Cardinal; const Args: array of const): Cardinal; $[SysUtils.pas
功能 返回按指定方式格式化一個數組常量到緩衝區Buffer中
說明 <NULL>
參考 <NULL>
例子 <參見Format>
━━━━━━━━━━━━━━━━━━━━━
函數 function FloatToStr(Value: Extended): string; $[SysUtils.pas
功能 返回浮點數Value轉換成字符串
說明 當浮點數大等於1E15將採用科學記數法
參考 function SysUtils.FloatToText
例子 Edit1.Text := FloatToStr(Now);
━━━━━━━━━━━━━━━━━━━━━
函數 function CurrToStr(Value: Currency): string; $[SysUtils.pas
功能 返回貨幣數Value轉換成字符串
說明 貨幣數只保留四位小數
參考 function SysUtils.FloatToText
例子 Edit1.Text := CurrToStr(Now);
━━━━━━━━━━━━━━━━━━━━━
函數 function FloatToCurr(const Value: Extended): Currency; $[SysUtils.pas
功能 返回浮點數Value轉換成貨幣數
說明 如果浮點數Value超出範圍則將觸發異常
參考 const SysUtiles.MinCurrency;const SysUtiles.MaxCurrency
例子 Edit1.Text := CurrToStr(FloatToCurr(Now));
━━━━━━━━━━━━━━━━━━━━━
函數 function FloatToStrF(Value: Extended; Format: TFloatFormat; Precision, Digits: Integer): string; $[SysUtils.pas
功能 返回浮點數以指定格式轉換成字符串
說明 Precision指定精度;Digits指定小數寬度
參考 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
功能 返回貨幣類型以指定格式轉換成字符串
說明 Digits指定小數寬度
參考 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
功能 返回浮點數以指定格式轉換成指針字符串的內存大小
說明 Precision指定精度;Digits指定小數寬度
參考 <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(
━━━━━━━━━━━━━━━━━━━━━
函數 function FormatFloat(const Format: string; Value: Extended): string; $[SysUtils.pas
功能 返回浮點數類型以指定格式字符串Format轉換成字符串
說明 FormatFloat(',.00', 1234567890) = '1,234,567,890.00'
參考 function SysUtils.FloatToTextFmt
例子 Edit1.Text := FormatFloat(Edit2.Text, StrToFloatDef(Edit3.Text, 0));
━━━━━━━━━━━━━━━━━━━━━
函數 function FormatCurr(const Format: string; Value: Currency): string; $[SysUtils.pas
功能 返回貨幣類型以指定格式字符串Format轉換成字符串
說明 FormatCurr(',.00', 1234567890) = '1,234,567,890.00'
參考 function SysUtils.FloatToTextFmt
例子 Edit1.Text := FormatCurr(Edit2.Text, StrToCurrDef(Edit3.Text, 0));
━━━━━━━━━━━━━━━━━━━━━
函數 function FloatToTextFmt(Buf: PChar; const Value; ValueType: TFloatValue; Format: PChar): Integer; $[SysUtils.pas
功能 返回浮點數以指定格式字符串Format轉換成指針字符串的內存大小
說明 ValueType指定無類型參數Value的類型
參考 <NULL>
例子
///////Begin FloatToTextFmt
procedure TForm1.Button1Click(Sender: TObject);
var
vBuffer: array[0..255] of Char;
E: Extended;
begin
E := StrToFloatDef(Edit1.Text, 0);
SpinEdit1.Value := FloatToTextFmt(vBuffer, E,
fvExtended, PChar(Edit2.Text));
Edit3.Text := Copy(vBuffer, 1, SpinEdit1.Value);
end;
///////End FloatToTextFmt
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToFloat(const S: string): Extended; $[SysUtils.pas
功能 返回字符串S轉換成浮點數
說明 字符串非浮點數表達時將引起異常
參考 function SysUtils.TextToFloat
例子 var E: Extended; begin E := StrToFloat(Edit1.Text); end;
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToFloatDef(const S: string; const Default: Extended): Extended; $[SysUtils.pas
功能 返回字符串S轉換成浮點數
說明 字符串非浮點數表達時則返回默認值Default
參考 function SysUtils.TextToFloat
例子 var E: Extended; begin E := StrToFloatDef(Edit1.Text, 0); end;
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToFloat(const S: string; out Value: Extended): Boolean; overload; $[SysUtils.pas
函數 function TryStrToFloat(const S: string; out Value: Single): Boolean; overload; $[SysUtils.pas
函數 function TryStrToFloat(const S: string; out Value: Double): Boolean; overload; $[SysUtils.pas
功能 返回字符串S轉換成浮點數Value是否成功
說明 字符串非浮點數表達時返回False並且Value將輸出爲不確定的值
參考 function SysUtils.TextToFloat
例子
///////Begin TryStrToFloat
procedure TForm1.Button1Click(Sender: TObject);
var
E: Extended;
begin
CheckBox1.Checked := TryStrToFloat(Edit1.Text, E);
Edit2.Text := FormatFloat('', E);
end;
///////End TryStrToFloat
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToCurr(const S: string): Currency; $[SysUtils.pas
功能 返回字符串S轉換成貨幣數
說明 字符串非貨幣數表達時將引起異常
參考 function SysUtils.TextToFloat
例子 var C: Currency; begin C := StrToCurr(Edit1.Text); end;
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToCurrDef(const S: string; const Default: Currency): Currency; $[SysUtils.pas
功能 返回字符串S轉換成貨幣數
說明 字符串非貨幣數表達時則返回默認值Default
參考 function SysUtils.TextToFloat
例子 var C: Currency; begin C := StrToCurrDef(Edit1.Text, 0); end;
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToCurr(const S: string; out Value: Currency): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成貨幣數Value是否成功
說明 字符串非貨幣數表達時返回False並且Value將輸出爲不確定的值
參考 function SysUtils.TextToFloat
例子
///////Begin TryStrToCurr
procedure TForm1.Button1Click(Sender: TObject);
var
C: Currency;
begin
CheckBox1.Checked := TryStrToCurr(Edit1.Text, C);
Edit2.Text := FormatCurr('', C);
end;
///////End TryStrToCurr
━━━━━━━━━━━━━━━━━━━━━
函數 function TextToFloat(Buffer: PChar; var Value; ValueType: TFloatValue): Boolean; $[SysUtils.pas
功能 返回將指針字符串Buffer轉換成無類型變量Value
說明 ValueType指定無類型參數Value的類型
參考 <NULL>
例子
///////Begin TextToFloat
procedure TForm1.Button1Click(Sender: TObject);
var
E: Extended;
begin
CheckBox1.Checked := TextToFloat(PChar(Edit1.Text), E,
fvExtended);
Edit2.Text := FormatFloat('', E);
end;
///////End TextToFloat
━━━━━━━━━━━━━━━━━━━━━
函數 function DateToStr(const DateTime: TDateTime): string; $[SysUtils.pas
功能 返回日期DateTime轉換成字符串
說明 轉換格式由系統變量ShortDateFormat控制
參考 function SysUtils.DateTimeToString;var SysUtils.ShortDateFormat
例子 Edit1.Text := DateToStr(Date);
━━━━━━━━━━━━━━━━━━━━━
函數 function TimeToStr(const DateTime: TDateTime): string; $[SysUtils.pas
功能 返回時間DateTime轉換成字符串
說明 轉換格式由系統變量LongTimeFormat控制
參考 function SysUtils.DateTimeToString;var SysUtils.LongTimeFormat
例子 Edit1.Text := TimeToStr(Date);
━━━━━━━━━━━━━━━━━━━━━
函數 function DateTimeToStr(const DateTime: TDateTime): string; $[SysUtils.pas
功能 返回日期時間DateTime轉換成字符串
說明 轉換格式由系統變量ShortDateFormat和LongTimeFormat控制
參考 function SysUtils.DateTimeToString
例子 Edit1.Text := DateTimeToStr(Now);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToDate(const S: string): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成日期
說明 字符非日期表達時將引起異常
參考 function SysUtils.TryStrToDate
例子 DateTimePicker1.Date := StrToDate(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToDateDef(const S: string; const Default: TDateTime): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成日期
說明 字符非日期表達時則返回默認值Default
參考 function SysUtils.TryStrToDate
例子 DateTimePicker1.Date := StrToDateDef(Edit1.Text, Date);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToDate(const S: string; out Value: TDateTime): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成日期Value是否成功
說明 字符非日期表達時返回False並且Value將輸出爲0
參考 <NULL>
例子
///////Begin TryStrToDate
procedure TForm1.Button1Click(Sender: TObject);
var
vDateTime: TDateTime;
begin
CheckBox1.Checked := TryStrToDate(Edit1.Text, vDateTime);
DateTimePicker1.Date := vDateTime;
end;
///////End TryStrToDate
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToTime(const S: string): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成時間
說明 字符非時間表達時將引起異常
參考 function SysUtils.TryStrToTime
例子 DateTimePicker1.Time := StrToTime(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToTimeDef(const S: string; const Default: TDateTime): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成時間
說明 字符非時間表達時則返回默認值Default
參考 function SysUtils.TryStrToTime
例子 DateTimePicker1.Time := StrToTimeDef(Edit1.Text, Time);
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToTime(const S: string; out Value: TDateTime): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成時間Value是否成功
說明 字符非時間表達時返回False並且Value將輸出爲0
參考 <NULL>
例子
///////Begin TryStrToTime
procedure TForm1.Button1Click(Sender: TObject);
var
vDateTime: TDateTime;
begin
CheckBox1.Checked := TryStrToTime(Edit1.Text, vDateTime);
DateTimePicker1.Time := vDateTime;
end;
///////End TryStrToTime
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToDateTime(const S: string): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成日期時間
說明 字符非日期時間表達時將引起異常
參考 function SysUtils.TryStrToDateTime
例子 Edit1.Text := DateTimeToStr(StrToDateTime(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrToDateTimeDef(const S: string; const Default: TDateTime): TDateTime; $[SysUtils.pas
功能 返回字符串S轉換成日期時間
說明 字符非日期時間表達時則返回默認值Default
參考 function SysUtils.TryStrToDateTime
例子 Edit1.Text := DateTimeToStr(StrToDateTimeDef(Edit2.Text, Now));
━━━━━━━━━━━━━━━━━━━━━
函數 function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean; $[SysUtils.pas
功能 返回字符串S轉換成日期時間Value是否成功
說明 字符非日期時間表達時返回False並且Value將輸出爲0
參考 <NULL>
例子
///////Begin TryStrToDateTime
procedure TForm1.Button1Click(Sender: TObject);
var
vDateTime: TDateTime;
begin
CheckBox1.Checked := TryStrToDateTime(Edit1.Text, vDateTime);
Edit2.Text := DateTimeToStr(vDateTime);
end;
///////End TryStrToDateTime
━━━━━━━━━━━━━━━━━━━━━
函數 procedure DateTimeToString(var Result: string; const Format: string; DateTime: TDateTime); $[SysUtils.pas
功能 用指定的格式Format來格式化日期時間DateTime並返回到字符串Result中
說明 <參見FormatDateTime>
參考 function System.SetString
例子 <參見FormatDateTime>
━━━━━━━━━━━━━━━━━━━━━
函數 function GetLocaleStr(Locale, LocaleType: Integer; const Default: string): string; platform; $[SysUtils.pas
功能 返回當前系統指定參數的字符串值
說明 GetLocaleStr(GetThreadLocale, LOCALE_SLANGUAGE, '') = '中文(中國)'
參考 function Windows.GetLocaleInfo
例子 Edit1.Text := GetLocaleStr(GetThreadLocale, SpinEdit1.Value, '<NULL>');
━━━━━━━━━━━━━━━━━━━━━
函數 function GetLocaleChar(Locale, LocaleType: Integer; Default: Char): Char; platform; $[SysUtils.pas
功能 返回當前系統指定參數的字符值
說明 GetLocaleChar(GetThreadLocale, LOCALE_STHOUSAND, #0) = ','
參考 function Windows.GetLocaleInfo
例子 Edit1.Text := GetLocaleChar(GetThreadLocale, LOCALE_SLANGUAGE, #0);
━━━━━━━━━━━━━━━━━━━━━
函數 function ByteType(const S: string; Index: Integer): TMbcsByteType; $[SysUtils.pas
功能 返回字符串S位置Index上的字符在MBCS中類型
說明 多字節字符系統:Multi-Byte Character System (MBCS)
參考 var SysUtils.SysLocale
例子 SpinEdit1.Value := Ord(ByteType(Edit1.Text, SpinEdit2.Value));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType; $[SysUtils.pas
功能 返回指針字符串Str位置Index上的字符在MBCS中類型
說明 Index從0開始
參考 var SysUtils.SysLocale
例子 SpinEdit1.Value := Ord(StrByteType(PChar(Edit1.Text), SpinEdit2.Value));
━━━━━━━━━━━━━━━━━━━━━
函數 function ByteToCharLen(const S: string; MaxLen: Integer): Integer; $[SysUtils.pas
功能 返回字符串S中有多少個多字節字符
說明 MaxLen指定處理字符個數
參考 function SysUtils.ByteToCharIndex
例子 SpinEdit1.Value := ByteToCharLen(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function CharToByteLen(const S: string; MaxLen: Integer): Integer; $[SysUtils.pas
功能 返回字符串S中有多少個字符
說明 MaxLen指定處理多字節字符個數
參考 var SysUtils.SysLocale
例子 SpinEdit1.Value := CharToByteLen(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function ByteToCharIndex(const S: string; Index: Integer): Integer; $[SysUtils.pas
功能 返回字符位置對應的多字節字符位置
說明 ByteToCharIndex('你好', 2) = 1;ByteToCharIndex('你好', 3) = 2
參考 function SysUtils.NextCharIndex
例子 SpinEdit1.Value := ByteToCharIndex(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function CharToByteIndex(const S: string; Index: Integer): Integer; $[SysUtils.pas
功能 返回多字節字符位置對應的字符起始位置
說明 CharToByteIndex('你好', 1) = 1;CharToByteIndex('你好', 2) = 3
參考 function System.Length
例子 SpinEdit1.Value := CharToByteIndex(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function StrCharLength(const Str: PChar): Integer; $[SysUtils.pas
功能 返回第一個字符的寬度
說明 參數爲空則返回0
參考 function Windows.CharNext
例子 SpinEdit1.Value := StrCharLength(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function StrNextChar(const Str: PChar): PChar; $[SysUtils.pas
功能 返回字符指針Str的下一個字符指針
說明 StrNextChar('1234') = '234';
參考 function Windows.CharNext
例子 Edit2.Text := StrNextChar(PChar(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function CharLength(const S: String; Index: Integer): Integer; $[SysUtils.pas
功能 返回字符串中指定位置的字符寬度
說明 CharLength('English漢', 1) = 1;CharLength('English漢', 8) = 2
參考 function System.Assert;function SysUtils.StrCharLength
例子 SpinEdit1.Value := CharLength(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function NextCharIndex(const S: String; Index: Integer): Integer; $[SysUtils.pas
功能 返回下一個字符的位置
說明 CharLength('你好', 1) = 3;CharLength('你好', 3) = 5
參考 function System.Assert;function SysUtils.StrCharLength
例子 SpinEdit1.Value := NextCharIndex(Edit1.Text, SpinEdit2.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function IsPathDelimiter(const S: string; Index: Integer): Boolean; $[SysUtils.pas
功能 返回字符串S中指定位置Index上是否是一個路徑分隔符
說明 IsPathDelimiter('C:/Windows', 3) = True
參考 const SysUtils.PathDelim;function SysUtils.ByteType
例子 CheckBox1.Checked := IsPathDelimiter(Edit1.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean; $[SysUtils.pas
功能 返回字符串S中指定位置Index上是否是一個分隔符Delimiters
說明 IsDelimiter('@', '[email protected]', 8) = True
參考 function SysUtils.ByteType
例子 CheckBox1.Checked := IsDelimiter(Edit1.Text, Edit2.Text, SpinEdit1.Value);
━━━━━━━━━━━━━━━━━━━━━
函數 function IncludeTrailingPathDelimiter(const S: string): string; $[SysUtils.pas
功能 返回包括最後路徑分隔符
說明 最後一個字符是路徑分隔符則不變;否則加上一個路徑分隔符返回
參考 function SysUtils.IsPathDelimiter;function System.Length
例子 Edit1.Text := IncludeTrailingPathDelimiter(Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function IncludeTrailingBackslash(const S: string): string; platform; $[SysUtils.pas
功能 返回包括最後斜線
說明 Result := IncludeTrailingPathDelimiter(S);
參考 function SysUtils.IncludeTrailingPathDelimiter
例子 Edit1.Text := IncludeTrailingBackslash(Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function ExcludeTrailingPathDelimiter(const S: string): string; $[SysUtils.pas
功能 返回排除最後路徑分隔符
說明 最後一個字符不是路徑分隔符則不變;否則減去最後的路徑分隔符返回
參考 function SysUtils.IsPathDelimiter;function System.Length;function System.SetLength
例子 Edit1.Text := ExcludeTrailingPathDelimiter(Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function ExcludeTrailingBackslash(const S: string): string; platform; $[SysUtils.pas
功能 返回排除最後斜線
說明 Result := ExcludeTrailingPathDelimiter(S)
參考 function SysUtils.ExcludeTrailingPathDelimiter
例子 Edit1.Text := ExcludeTrailingBackslash(Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function LastDelimiter(const Delimiters, S: string): Integer; $[SysUtils.pas
功能 返回最後一個分隔符的位置
說明 LastDelimiter('.', 'kingron.myetang.com') = 16
參考 function SysUtils.StrScan;function SysUtils.ByteType
例子 SpinEdit1.Value := LastDelimiter(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiCompareFileName(const S1, S2: string): Integer; $[SysUtils.pas
功能 返回比較兩個文件名
說明 當S1>S2返回值>0;當S1<S2返回值<0;當S1=S2返回值=0;區分大小寫
參考 function SysUtils.AnsiCompareStr
例子 SpinEdit1.Value := AnsiCompareFileName(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function SameFileName(const S1, S2: string): Boolean; $[SysUtils.pas
功能 返回兩個文件名是否相等
說明 區分大小寫
參考 function SysUtils.AnsiCompareFileName
例子 CheckBox1.Checked := SameFileName(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiLowerCaseFileName(const S: string): string; $[SysUtils.pas
功能 返回小寫文件名
說明 在非多字節字符系統上相當於AnsiLowerCase
參考 function SysUtils.AnsiLowerCase
例子 Edit2.Text := AnsiLowerCaseFileName(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiUpperCaseFileName(const S: string): string; $[SysUtils.pas
功能 返回大寫文件名
說明 在非多字節字符系統上相當於AnsiUpperCase
參考 function SysUtils.AnsiUpperCase
例子 Edit2.Text := AnsiUpperCaseFileName(Edit1.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiPos(const Substr, S: string): Integer; $[SysUtils.pas
功能 返回子串Substr在字符中第一次出現的位置
說明 不存在則返回0
參考 SysUtils.AnsiStrPos
例子 SpinEdit1.Value := AnsiPos(Edit1.Text, Edit2.Text);
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrPos(Str, SubStr: PChar): PChar; $[SysUtils.pas
功能 返回指針子串Substr在指針字符中第一次出現的指針位置
說明 不存在則返回nil
參考 function SysUtils.StrByteType
例子 Edit3.Text := AnsiStrPos(PChar(Edit1.Text), PChar(Edit2.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrRScan(Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr最後一個出現的地址
說明 支持多字節字符系統;AnsiStrRScan('kingron.myetang.com', '.') = '.com'
參考 function SysUtils.AnsiStrScan
例子 Edit2.Text := AnsiStrScan(PChar(Edit1.Text), '.');
━━━━━━━━━━━━━━━━━━━━━
函數 function AnsiStrScan(Str: PChar; Chr: Char): PChar; $[SysUtils.pas
功能 返回在指針字符串Str搜索字符Chr第一個出現的地址
說明 支持多字節字符系統;AnsiStrRScan('kingron.myetang.com', '.') = '.myetang.com'
參考 function SysUtils.StrScan
例子 Edit2.Text := AnsiStrScan(PChar(Edit1.Text), '.');

━━━━━━━━━━━━━━━━━━━━━
函數 function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string; $[SysUtils.pas
功能 返回替換後的字符串
說明 rfReplaceAll爲替換全部內容;rfIgnoreCase爲忽略大小寫
參考 function SysUtils.AnsiUpperCase;function SysUtils.AnsiPos;function System.Copy
例子
///////Begin StringReplace
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Values['[]'] :=
StringReplace(Edit1.Text, Edit2.Text, Edit3.Text, []);
Memo1.Lines.Values['[rfReplaceAll]'] :=
StringReplace(Edit1.Text, Edit2.Text, Edit3.Text, [rfReplaceAll]);
Memo1.Lines.Values['[rfIgnoreCase]'] :=
StringReplace(Edit1.Text, Edit2.Text, Edit3.Text, [rfIgnoreCase]);
Memo1.Lines.Values['[rfReplaceAll, rfIgnoreCase]'] :=
StringReplace(Edit1.Text, Edit2.Text, Edit3.Text, [rfReplaceAll, rfIgnoreCase]);
end;
///////End StringReplace
━━━━━━━━━━━━━━━━━━━━━
函數 function StringToGUID(const S: string): TGUID; $[SysUtils.pas
功能 返回字符串S轉換成全局標識
說明 如果字符串非法將觸發異常
參考 fuction Windows.Succeeded
例子 Edit2.Text := GUIDToString(StringToGUID(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━
函數 function GUIDToString(const GUID: TGUID): string; $[SysUtils.pas
功能 返回全局標識GUID轉換成字符串
說明 <NULL>
參考 fuction Windows.Succeeded
例子 Edit2.Text := GUIDToString(StringToGUID(Edit1.Text));
━━━━━━━━━━━━━━━━━━━━━

=================================================
日期與時間函數 (Date and Time Routines)
Unit: SysUtils
========================================
Date 傳回今天日期。function Date: TDateTime;
DateTimeToStr 將時間格式轉爲字串。function DateTimeToStr(DateTime: TDateTime):String;
DateTimeToString 將時間格式轉爲字串。
procedure DateTimeToString(var Result: string;const Format: string;DateTime: TDateTime);
DateToStr 將日期格式轉爲字串。function DateToStr(Date: TDateTime): String;
DayOfWeek 傳回今天星期幾。function DayOfWeek(Date: TDateTime): Integer;
DecodeDate 分解所指定的日期爲年、月、日。
procedure DecodeDate(Date: TDateTime;var Year, Month, Day:Word);
DecodeTime 分解所指定的日期爲時、分、秒。
procedure DecodeTime(Time: TDateTime;var Hour, Min, Sec,MSec: Word);
EncodeDate 傳回將年、月、日所組合的日期格式。
function EncodeDate(Year, Month, Day: Word):TDateTime;
EncodeTime 傳回將時、分、秒所組合的時間格式。
function EncodeTime(Hour, Min, Sec, MSec:Word): TDateTime;
FormatDateTime 以指定的格式傳回日期時間。
function FormatDateTime(const Format: string;DateTime: TDateTime):String;
Now 傳回現在的日期時間。function Now: TDateTime;
StrToDate 將字串轉爲日期格式。function StrToDate(const S:string): TDateTime;
StrToDateTime 將字串轉爲日期時間格式function StrToDateTime(const S: string): TDateTime;
StrToTime 將字串轉爲時間格式。function StrToTime(const S:string): TDateTime;
Time 傳回現在時間。function Time: TDateTime;
TimeToStr 將時格式轉爲字串。function TimeToStr(Time:TDateTime): String;
========================================
檔案管理函數
Unit: SysUtils
========================================
ChangeFileExt 變更檔案的延伸檔名。
function ChangeFileExt(const FileName,Extension: string):string;
DateTimeToFileDate 將Delphi 的日期格式轉換爲DOS的日期格式。
functionDateTimeToFileDate(DateTime:TDateTime): Longint;
DeleteFile 刪除一個檔案。
function DeleteFile(const FileName: string):Boolean;
DiskFree 傳回磁碟的可用空間。function DiskFree(Drive: Byte): Longint;
DiskSize 傳回指定磁碟的容量大小。function DiskSize(Drive: Byte): Longint;
ExpandFileName 傳回一個完整的路徑及檔名字串。
function expandFileName(const FileName: string):string;
ExtractFileExt 傳回檔案的延伸檔名。function ExtractFileExt(const FileName string):string;
ExtractFileName 傳回檔案的檔名。function ExtractFileName(const FileName: string):string;
ExtractFilePath 傳回檔案的路徑。function ExtractFilePath(const FileName: string):string;
FileAge 傳回檔案的年紀function FileAge(const FileName: string):Longint;
FileCreate 以指定檔名建立一個檔案。function FileCreate(const FileName: string):Integer;
FileClose 關閉指定的檔案。procedureFileClose(Handle: Integer);
FileDateToDateTime 將DOS 的日期格式轉爲Delphi 的日期格式。
function FileDateToDateTime(FileDate: Longint):TDateTime;
FileExists 判別檔案是否存在。function FileExists(const FileName: string):Boolean;
FileGetAttr 傳回檔案屬性。function FileGetAttr(const FileName: string):Integer;
FileGetDate 傳回檔案的日期及時間。function FileGetDate(Handle: Integer): Longint;
FileRead 從指定的檔案讀入資料。
function FileRead(Handle:Integer; var Buffer;Count:Longint):Longint;
FileSearch 在目錄列中搜尋指定的檔案。function FileSearch(constName, DirList: string):string;
FileSeek 改變檔案遊標的位置。function FileSeek(Handle: Integer;Offset: Longint;Origin: Integer):Longint;
FileSetAttr 設定檔案屬性。function FileSetAttr(const FileName: string;Attr:Integer): Integer;
FileSetDate 設定檔案的日期及時間。procedure FileSetDate(Handle: Integer; Age:Longint);
FileOpen 開啓檔案。function FileOpen(const FileName: string; Mode:Word): Integer;
FileWrite 寫資料到檔案。function FileWrite(Handle:Integer;const Buffer; Count:Longint): Longint;
FindClose 終止找尋第一個/下一個的動作。procedure FindClose(var SearchRec: TSearchRec);
FindFirst 尋找第一個符合的檔案並設定其屬性。
function FindFirst(const Path: string;Attr: Word; var F:TSearchRec): Integer;
FindNext 傳回下一個符合的檔案。function FindNext(var F:TSearchRec): Integer;
RenameFile 變更檔名。function RenameFile(const OldName,NewName: string):Boolean;

怎樣在 CASE 語句中使用字符串
/////////////////////////////////////////

首先建立 CaseString 函數,用於獲取某字符串在一個字符串數組中的順序:

function CaseString (const s: string;
const x: array of string): Integer;
var i: Integer;
begin
Result:= -1; // Default return parameter
for i:= Low (x) to High (x) do begin
if s = x[i] then begin Result:= i; Exit; end;
end;
end;

Low() 提供第一個數組成員(通常是0),High() 則返回最後一個。因爲 CaseString 返回的是待查字符串在字符串數組中的位置,因此,它可以被直接用到 CASE 語句中:

search:= 'delphi3000';
case CaseString (search, ['delphi3000',
'delphipages',
'Torry's']) of
0: s:= 'Excellent!';
1: s:= 'Good source';
2: s:= 'Not bad!';
end;

copy(str,pos,num) 從str字符串的pos處開始,截取num個字符的串返回.假設str爲'abcdef',copy(str,3,2)='cd',copy(str,4,10)='def'
concat(str1,str2{,strn}) 把各自變量連接起來,返回連接後的字符串(長度不能超過255)

length(str) 返回str的字符個數,即其長度.

pos(obj,target) 在target字符串中找出第一個出現obj的第一個字符位置,如果找不到,返回0.

AnsiStrLastChar('你好')結果是“好”。如果有半個漢字出現,返回這半個漢字。二者字符串長度分別爲2和1。

CompareStr - 區分大小寫
CompareText - 不區分大小寫

////////////////////////////////////////////////////////
{判斷字符是否是數字}
function IsDigit(ch: char): boolean;
begin
Result := ch in ['0'..'9'];
end;
{判斷字符是否是大寫字符}
function IsUpper(ch: char): boolean;
begin
Result := ch in ['A'..'Z'];
end;

{判斷字符是否是小寫字符}
function IsLower(ch: char): boolean;
begin
Result := ch in ['a'..'z'];
end;

{轉換爲大寫字符}
function ToUpper(ch: char): char;
begin
Result := chr(ord(ch) and $DF);
end;

{轉換爲小寫字符}
function ToLower(ch: char): char;
begin
Result := chr(ord(ch) or $20);
end;

{ Capitalizes first letter of every word in s }
function Proper(const s: string): string;
var
i: Integer;
CapitalizeNextLetter: Boolean;
begin
Result := LowerCase(s);
CapitalizeNextLetter := True;
for i := 1 to Length(Result) do
begin
if CapitalizeNextLetter and IsLower(Result[i]) then
Result[i] := ToUpper(Result[i]);
CapitalizeNextLetter := Result[i] = ' ';
end;
end;
////////////////////////////////////////////////////////////
{返回兩個子字符串之間字符的個數}
Function p2pcount( s, ss1, ss2 : string ): integer;
var i, j, slen : integer;
begin
i := pos( ss1, s );
j := pos( ss2, s );
slen := Length(ss2);
if j >= i then Result := j - i + slen else Result := 0;
end;

{更快速的字符查詢,快40%}
function ScanStr(ToScan: PChar; Sign: Char):PChar;
begin
Result:= nil;
if ToScan <> nil then
while (ToScan^ <> #0) do begin
if ToScan^ = Sign then begin
Result:= ToScan;
break;
end;
inc(ToScan);
end;
end;
/////////////////////////////
替換字符串中子串的函數,他可以從字符串中找出指定子串,並替換爲另一子串。
function replacing(S,source,target:string):string;
var site,StrLen:integer;
begin
{source在S中出現的位置}
site:=pos(source,s);

{source的長度}
StrLen:=length(source);

{刪除source字符串}
delete(s,site,StrLen);

{插入target字符串到S中}
insert(target,s,site);

{返回新串}
replacing:=s;
end;
///////////////////////
另兩個替換字符串中子串的函數
function repl_substr( sub1, sub2, s: string ): string;
var i: integer;
begin
repeat
i := pos( sub1, s ) ;
if i > 0 then begin
delete( s, i, Length(sub1));
insert( sub2, s, i );
end;
until i < 1;
Result := s;
end;

function ReplaceText(const S,ReplacePiece,ReplaceWith: String):String;

Var Position: Integer;
TempStr: String;
begin
Position := Pos(ReplacePiece,S);
if Position > 0 then Begin
TempStr := S;
Delete(TempStr,1,Position-1+Length(ReplacePiece));
Result :=
Copy(S,1,Position-1)+ReplaceWith+ReplaceText(TempStr,ReplacePiece,ReplaceWith)

End else Result := S;
end;
////////////////////////
替換全部子字符串的函數

function ReplaceSub(str, sub1, sub2: String): String;
var
aPos: Integer;
rslt: String;

begin
aPos := Pos(sub1, str);
rslt := '';
while (aPos <> 0) do begin
rslt := rslt + Copy(str, 1, aPos - 1) + sub2;
Delete(str, 1, aPos + Length(sub1));
aPos := Pos(sub1, str);
end;
Result := rslt + str;
end;

/////////////////////////
在字符串左右填充指定數量的指定字符
function UT_PadString(inString :string; maxLength :integer; padChar :char;
left :boolean) :string;
begin
result := inString;
while (Length(result) < maxLength) do
if (left) then
result := padChar + result
else
result := result + padChar;
end;
/////////////////////////////////////
提取字符串中指定子字符串前的字符串
Function Before ( Src:string ; Var S:string ) : string ;
Var
F : Word ;

begin
F := POS (Src,S) ;
if F=0 then
Before := S
else
Before := COPY(S,1,F-1) ;
end ;
//////////////////////////////////
提取字符串中指定子字符串後的字符串
Function After ( Src:string ; Var S:string ) : string ;
Var
F : Word ;

begin
F := POS (Src,S) ;
if F=0 then
After := ''
else
After := COPY(S,F+length(src),length(s)) ;
end ;
////////////////////////////////////
判斷字符串是否可以轉換爲整數
function IsIntStr(const S: string): boolean;
begin
Result:=StrToIntDef(S,0)=StrToIntDef(S,1);
end;
//////////////////////////////////////
從字符串中刪除指定字符串
procedure RemoveInvalid(what, where: string): string;

var
tstr: string;

begin
tstr:=where;
while pos(what, tstr)>0 do
tstr:=copy(tstr,1,pos(what,tstr)-1) +
copy(tstr,pos(what,tstr)+length(tstr),length(tstr));
Result:=tstr;
end;
用法:
NewStr:=RemoveInvalid('<invalid>','This <invalid> is my string and I wan to
remove the word <invalid>');
///////////////////////////////////////////
根據某個字符分割字符串的函數
procedure SeparateTerms(s : string;Separator : char;Terms : TStringList);
{ This browses a string and divide it into terms whenever the given
separator is found. The separators will be removed }
var
hs : string;
p : integer;

begin
Terms.Clear; // First remove all remaining terms
if Length(s)=0 then // Nothin' to separate
Exit;
p:=Pos(Separator,s);
while P<>0 do
begin
hs:=Copy(s,1,p-1); // Copy term
Terms.Add(hs); // Add to list
Delete(s,1,p); // Remove term and separator
p:=Pos(Separator,s); // Search next separator
end;
if Length(s)>0 then
Terms.Add(s); // Add remaining term
end;
==========
= 用 法
==========

var
Terms : TStringList;
i : integer;

const
TestStr = '1st term;2nd term;3rd term';

begin
Terms:=TStringList.Create;
SeparateTerms(TestStr,';',Terms);
for i:=0 to terms.Count-1 do
ShowMessage(Terms.Strings[i]);
Terms.Free;
end;
/////////////////////////////
根據一組字符分割字符串的函數
type
Charset = set of Char;
var
f : Text;
s : String;

procedure WriteStringSplitted(var s: String; Separators: Charset);
var
a,e : Integer; {anfang und ende des w鰎tchens}
begin
a := 1;
for e := 1 to Length(s) do
if s[e] in Separators then begin
WriteLn(Copy(s, a, e-a));
a := e + 1;
end;
WriteLn(Copy(s, a, e-a+1));
end;

begin
Assign(f, 'c:/dingsbums/text.txt');
Reset(f);
while not EOF(f) do begin
ReadLn(f,s);
WriteStringSplitted(s, [':', ',']);
end;
Close(f);
end.
//////////////////////////////////////////////////

{===============================================================}
{ 函數 : RESULTSTRING = HexToBin(HEXSTRING)
{ 目的 : 把十六進制字符串轉換爲二進制字符串
{
{===============================================================}
{ 函數 : RESULTINTEGER = HexCharToInt(HEXCHAR)
{ 目的 : 轉換一個十六進制字符爲整數
{===============================================================}
{ 函數 : RESULTSTRING = HexCharToBin(HEXCHAR)
{ 目的 : 轉換一個十六進制字符爲二進制字符串
{===============================================================}
{ 函數 : RESULTINTEGER = Pow(BASE,POWER)
{ 目的 : 指數函數
{===============================================================}
{ 函數 : RESULTINTEGER = BinStrToInt(BINSTRING)
{ 目的 : 把二進制字符串轉換爲整數
{===============================================================}
{ 函數 : RESULTSTRING = DecodeSMS7Bit (PDUSTRING)
{ 目的 : 解碼一個7-bit SMS (GSM 03.38) 爲ASCII碼
{===============================================================}
{ 函數 : RESULTSTRING = ReverseStr (SOURCESTRING)
{ 目的 : 反轉一個字符串
{===============================================================}

unit BinHexTools;
interface

function HexToBin(HexNr : string): string;
function HexCharToInt(HexToken : char):Integer;
function HexCharToBin(HexToken : char): string;
function pow(base, power: integer): integer;
function BinStrToInt(BinStr : string) : integer;
function DecodeSMS7Bit(PDU : string):string;
function ReverseStr(SourceStr : string) : string;

implementation

uses sysutils, dialogs;

function HexCharToInt(HexToken : char):Integer;
begin
{if HexToken>#97 then HexToken:=Chr(Ord(HexToken)-32);
{ use lowercase aswell }

Result:=0;

if (HexToken>#47) and (HexToken<#58) then { chars 0....9 }
Result:=Ord(HexToken)-48
else if (HexToken>#64) and (HexToken<#71) then { chars A....F }
Result:=Ord(HexToken)-65 + 10;
end;

function HexCharToBin(HexToken : char): string;
var DivLeft : integer;
begin
DivLeft:=HexCharToInt(HexToken); { first HEX->BIN }
Result:='';
{ Use reverse dividing }
repeat { Trick; divide by 2 }
if odd(DivLeft) then { result = odd ? then bit = 1 }
Result:='1'+Result { result = even ? then bit = 0 }
else
Result:='0'+Result;

DivLeft:=DivLeft div 2; { keep dividing till 0 left and length = 4 }
until (DivLeft=0) and (length(Result)=4); { 1 token = nibble = 4 bits }
end;

function HexToBin(HexNr : string): string;
{ only stringsize is limit of binnr }
var Counter : integer;
begin
Result:='';

for Counter:=1 to length(HexNr) do
Result:=Result+HexCharToBin(HexNr[Counter]);
end;

function pow(base, power: integer): integer;
var counter : integer;
begin
Result:=1;

for counter:=1 to power do
Result:=Result*base;
end;

function BinStrToInt(BinStr : string) : integer;
var counter : integer;
begin
if length(BinStr)>16 then
raise ERangeError.Create(#13+BinStr+#13+
'is not within the valid range of a 16 bit binary.'+#13);

Result:=0;

for counter:=1 to length(BinStr) do
if BinStr[Counter]='1' then
Result:=Result+pow(2,length(BinStr)-counter);
end;

function DecodeSMS7Bit(PDU : string):string;
var OctetStr : string;
OctetBin : string;
Charbin : string;
PrevOctet: string;
Counter : integer;
Counter2 : integer;
begin
PrevOctet:='';
Result:='';

for Counter:=1 to length(PDU) do
begin
if length(PrevOctet)>=7 then { if 7 Bit overflow on previous }
begin
if BinStrToInt(PrevOctet)<>0 then
Result:=Result+Chr(BinStrToInt(PrevOctet))
else Result:=Result+' ';

PrevOctet:='';
end;

if Odd(Counter) then { only take two nibbles at a time }
begin
OctetStr:=Copy(PDU,Counter,2);
OctetBin:=HexToBin(OctetStr);

Charbin:='';
for Counter2:=1 to length(PrevOctet) do
Charbin:=Charbin+PrevOctet[Counter2];

for Counter2:=1 to 7-length(PrevOctet) do
Charbin:=OctetBin[8-Counter2+1]+Charbin;

if BinStrToInt(Charbin)<>0 then Result:=Result+Chr(BinStrToInt(CharBin))
else Result:=Result+' ';

PrevOctet:=Copy(OctetBin,1,length(PrevOctet)+1);
end;
end;
end;

function ReverseStr(SourceStr : string) : string;
var Counter : integer;
begin
Result:='';

for Counter:=1 to length(SourceStr) do
Result:=SourceStr[Counter]+Result;
end;

end.
在Delphi中沒有前導0輸出的函數,如C語言中printf("%08d",10);就會輸"000000010",但是在實際應用中經常會用到此種函數,如財務等數據的輸出。如何實現?以下的代碼實現了這種功能,

function qd0str(const count,num:integer):String;
Var
s1,s2:String;
begin
s1:=IntToStr(Num);
s2:='00000000000000000000';
if (Length(s1)>=count) then
s2:=''
else if(count>20) then
SetLength(S2,20-Length(s1))
else
SetLength(S2,count-Length(s1));

Result:=S2+S1;
end;

函數的參數count爲輸出字符串的總長度,在函數中定義爲最大20。Num爲需要轉換成字符串的數據。
////////////////////////////////////////
function IntToLZStr(value : integer;digits : byte) : string;
var
Res : string;

begin
Res:=IntToStr(value);
while Length(Res)<digits do
Insert('0',res,1);
IntToLZStr:=Res;
end;

AdjustWindowRect 給定一種窗口樣式,計算獲得目標客戶區矩形所需的窗口大小
AnyPopup 判斷屏幕上是否存在任何彈出式窗口
ArrangeIconicWindows 排列一個父窗口的最小化子窗口
AttachThreadInput 連接線程輸入函數
BeginDeferWindowPos 啓動構建一系列新窗口位置的過程
BringWindowToTop 將指定的窗口帶至窗口列表頂部
CascadeWindows 以層疊方式排列窗口
ChildWindowFromPoint 返回父窗口中包含了指定點的第一個子窗口的句柄

ClientToScreen 判斷窗口內以客戶區座標表示的一個點的屏幕座標
CloseWindow 最小化指定的窗口
CopyRect 矩形內容複製
DeferWindowPos 該函數爲特定的窗口指定一個新窗口位置
DestroyWindow 清除指定的窗口以及它的所有子窗口
DrawAnimatedRects 描繪一系列動態矩形
EnableWindow 指定的窗口裏允許或禁止所有鼠標及鍵盤輸入
EndDeferWindowPos 同時更新DeferWindowPos調用時指定的所有窗口的位置及狀態
EnumChildWindows 爲指定的父窗口枚舉子窗口

EnumThreadWindows 枚舉與指定任務相關的窗口
EnumWindows 枚舉窗口列表中的所有父窗口
EqualRect 判斷兩個矩形結構是否相同
FindWindow 尋找窗口列表中第一個符合指定條件的頂級窗口
FindWindowEx 在窗口列表中尋找與指定條件相符的第一個子窗口
FlashWindow 閃爍顯示指定窗口
GetActiveWindow 獲得活動窗口的句柄
GetCapture 獲得一個窗口的句柄,這個窗口位於當前輸入線程,且擁有鼠標捕獲(鼠標活動由它接收)
GetClassInfo 取得WNDCLASS結構(或WNDCLASSEX結構)的一個副本,結構中包含了與指定類有關的信息

GetClassLong 取得窗口類的一個Long變量條目
GetClassName 爲指定的窗口取得類名
GetClassWord 爲窗口類取得一個整數變量
GetClientRect 返回指定窗口客戶區矩形的大小
GetDesktopWindow 獲得代表整個屏幕的一個窗口(桌面窗口)句柄
GetFocus 獲得擁有輸入焦點的窗口的句柄
GetForegroundWindow 獲得前臺窗口的句柄
GetLastActivePopup 獲得在一個給定父窗口中最近激活過的彈出式窗口的句柄
GetLastError 針對之前調用的api函數,用這個函數取得擴展錯誤信息

GetParent 判斷指定窗口的父窗口
GetTopWindow 搜索內部窗口列表,尋找隸屬於指定窗口的頭一個窗口的句柄
GetUpdateRect 獲得一個矩形,它描敘了指定窗口中需要更新的那一部分
GetWindow 獲得一個窗口的句柄,該窗口與某源窗口有特定的關係
GetWindowContextHelpId 取得與窗口關聯在一起的幫助場景ID
GetWindowLong 從指定窗口的結構中取得信息
GetWindowPlacement 獲得指定窗口的狀態及位置信息
GetWindowRect 獲得整個窗口的範圍矩形,窗口的邊框、標題欄、滾動條及菜單等都在這個矩形內

GetWindowText 取得一個窗體的標題(caption)文字,或者一個控件的內容
GetWindowTextLength 調查窗口標題文字或控件內容的長短
GetWindowWord 獲得指定窗口結構的信息
InflateRect 增大或減小一個矩形的大小
IntersectRect 這個函數在lpDestRect裏載入一個矩形,它是lpSrc1Rect與lpSrc2Rect兩個矩形的交集
InvalidateRect 屏蔽一個窗口客戶區的全部或部分區域
IsChild 判斷一個窗口是否爲另一窗口的子或隸屬窗口

IsIconic 判斷窗口是否已最小化
IsRectEmpty 判斷一個矩形是否爲空
IsWindow 判斷一個窗口句柄是否有效
IsWindowEnabled 判斷窗口是否處於活動狀態
IsWindowUnicode 判斷一個窗口是否爲Unicode窗口。這意味着窗口爲所有基於文本的消息都接收Unicode文字
IsWindowVisible 判斷窗口是否可見
IsZoomed 判斷窗口是否最大化
LockWindowUpdate 鎖定指定窗口,禁止它更新
MapWindowPoints 將一個窗口客戶區座標的點轉換到另一窗口的客戶區座標系統

MoveWindow 改變指定窗口的位置和大小
OffsetRect 通過應用一個指定的偏移,從而讓矩形移動起來
OpenIcon 恢復一個最小化的程序,並將其激活
PtInRect 判斷指定的點是否位於矩形內部
RedrawWindow 重畫全部或部分窗口
ReleaseCapture 爲當前的應用程序釋放鼠標捕獲
ScreenToClient 判斷屏幕上一個指定點的客戶區座標
ScrollWindow 滾動窗口客戶區的全部或一部分
ScrollWindowEx 根據附加的選項,滾動窗口客戶區的全部或部分

SetActiveWindow 激活指定的窗口
SetCapture 將鼠標捕獲設置到指定的窗口
SetClassLong 爲窗口類設置一個Long變量條目
SetClassWord 爲窗口類設置一個條目
SetFocusAPI 將輸入焦點設到指定的窗口。如有必要,會激活窗口
SetForegroundWindow 將窗口設爲系統的前臺窗口
SetParent 指定一個窗口的新父
SetRect 設置指定矩形的內容
SetRectEmpty 將矩形設爲一個空矩形
SetWindowContextHelpId 爲指定的窗口設置幫助場景(上下文)ID

SetWindowLong 在窗口結構中爲指定的窗口設置信息
SetWindowPlacement 設置窗口狀態和位置信息
SetWindowPos 爲窗口指定一個新位置和狀態
SetWindowText 設置窗口的標題文字或控件的內容
SetWindowWord 在窗口結構中爲指定的窗口設置信息
ShowOwnedPopups 顯示或隱藏由指定窗口所有的全部彈出式窗口
ShowWindow 控制窗口的可見性
ShowWindowAsync 與ShowWindow相似
SubtractRect 裝載矩形lprcDst,它是在矩形lprcSrc1中減去lprcSrc2得到的結果

TileWindows 以平鋪順序排列窗口
UnionRect 裝載一個lpDestRect目標矩形,它是lpSrc1Rect和lpSrc2Rect聯合起來的結果
UpdateWindow 強制立即更新窗口
ValidateRect 校驗窗口的全部或部分客戶區
WindowFromPoint 返回包含了指定點的窗口的句柄。忽略屏蔽、隱藏以及透明窗口

tsqgw (2002-03-14 14:48:00)
ActivateKeyboardLayout 激活一個新的鍵盤佈局。鍵盤佈局定義了按鍵在一種物理性鍵盤上的位置與含義
Beep 用於生成簡單的聲音
CharToOem 將一個字串從ANSI字符集轉換到OEM字符集
ClipCursor 將指針限制到指定區域
ConvertDefaultLocale 將一個特殊的地方標識符轉換成真實的地方ID
CreateCaret 根據指定的信息創建一個插入符(光標),並將它選定爲指定窗口的默認插入符
DestroyCaret 清除(破壞)一個插入符
EnumCalendarInfo 枚舉在指定“地方”環境中可用的日曆信息

EnumDateFormats 列舉指定的“當地”設置中可用的長、短日期格式
EnumSystemCodePages 枚舉系統中已安裝或支持的代碼頁
EnumSystemLocales 枚舉系統已經安裝或提供支持的“地方”設置
EnumTimeFormats 枚舉一個指定的地方適用的時間格式
ExitWindowsEx 退出windows,並用特定的選項重新啓動
ExpandEnvironmentStrings 擴充環境字串
FreeEnvironmentStrings 翻譯指定的環境字串塊
GetACP 判斷目前正在生效的ANSI代碼頁

GetAsyncKeyState 判斷函數調用時指定虛擬鍵的狀態
GetCaretBlinkTime 判斷插入符光標的閃爍頻率
GetCaretPos 判斷插入符的當前位置
GetClipCursor 取得一個矩形,用於描述目前爲鼠標指針規定的剪切區域
GetCommandLine 獲得指向當前命令行緩衝區的一個指針
GetComputerName 取得這臺計算機的名稱
GetCPInfo 取得與指定代碼頁有關的信息
GetCurrencyFormat 針對指定的“地方”設置,根據貨幣格式格式化一個數字
GetCursor 獲取目前選擇的鼠標指針的句柄

GetCursorPos 獲取鼠標指針的當前位置
GetDateFormat 針對指定的“當地”格式,對一個系統日期進行格式化
GetDoubleClickTime 判斷連續兩次鼠標單擊之間會被處理成雙擊事件的間隔時間
GetEnvironmentStrings 爲包含了當前環境字串設置的一個內存塊分配和返回一個句柄
GetEnvironmentVariable 取得一個環境變量的值
GetInputState 判斷是否存在任何待決(等待處理)的鼠標或鍵盤事件
GetKBCodePage 由GetOEMCP取代,兩者功能完全相同
GetKeyboardLayout 取得一個句柄,描述指定應用程序的鍵盤佈局

GetKeyboardLayoutList 獲得系統適用的所有鍵盤佈局的一個列表
GetKeyboardLayoutName 取得當前活動鍵盤佈局的名稱
GetKeyboardState 取得鍵盤上每個虛擬鍵當前的狀態
GetKeyboardType 瞭解與正在使用的鍵盤有關的信息
GetKeyNameText 在給出掃描碼的前提下,判斷鍵名
GetKeyState 針對已處理過的按鍵,在最近一次輸入信息時,判斷指定虛擬鍵的狀態
GetLastError 針對之前調用的api函數,用這個函數取得擴展錯誤信息
GetLocaleInfo 取得與指定“地方”有關的信息

GetLocalTime 取得本地日期和時間
GetNumberFormat 針對指定的“地方”,按特定的格式格式化一個數字
GetOEMCP 判斷在OEM和ANSI字符集間轉換的windows代碼頁
GetQueueStatus 判斷應用程序消息隊列中待決(等待處理)的消息類型
GetSysColor 判斷指定windows顯示對象的顏色
GetSystemDefaultLangID 取得系統的默認語言ID
GetSystemDefaultLCID 取得當前的默認系統“地方”
GetSystemInfo 取得與底層硬件平臺有關的信息

GetSystemMetrics 返回與windows環境有關的信息
GetSystemPowerStatus 獲得與當前系統電源狀態有關的信息
GetSystemTime 取得當前系統時間,這個時間採用的是“協同世界時間”(即UTC,也叫做GMT)格式
GetSystemTimeAdjustment 使內部系統時鐘與一個外部的時鐘信號源同步
GetThreadLocale 取得當前線程的地方ID
GetTickCount 用於獲取自windows啓動以來經歷的時間長度(毫秒)
GetTimeFormat 針對當前指定的“地方”,按特定的格式格式化一個系統時間

GetTimeZoneInformation 取得與系統時區設置有關的信息
GetUserDefaultLangID 爲當前用戶取得默認語言ID
GetUserDefaultLCID 取得當前用戶的默認“地方”設置
GetUserName 取得當前用戶的名字
GetVersion 判斷當前運行的Windows和DOS版本
GetVersionEx 取得與平臺和操作系統有關的版本信息
HideCaret 在指定的窗口隱藏插入符(光標)
IsValidCodePage 判斷一個代碼頁是否有效
IsValidLocale 判斷地方標識符是否有效

keybd_event 這個函數模擬了鍵盤行動
LoadKeyboardLayout 載入一個鍵盤佈局
MapVirtualKey 根據指定的映射類型,執行不同的掃描碼和字符轉換
MapVirtualKeyEx 根據指定的映射類型,執行不同的掃描碼和字符轉換
MessageBeep 播放一個系統聲音。系統聲音的分配方案是在控制面板裏決定的
mouse_event 模擬一次鼠標事件
OemKeyScan 判斷OEM字符集中的一個ASCII字符的掃描碼和Shift鍵狀態
OemToChar 將OEM字符集的一個字串轉換到ANSI字符集

SetCaretBlinkTime 指定插入符(光標)的閃爍頻率
SetCaretPos 指定插入符的位置
SetComputerName 設置新的計算機名
SetCursor 將指定的鼠標指針設爲當前指針
SetCursorPos 設置指針的位置
SetDoubleClickTime 設置連續兩次鼠標單擊之間能使系統認爲是雙擊事件的間隔時間
SetEnvironmentVariable 將一個環境變量設爲指定的值
SetKeyboardState 設置每個虛擬鍵當前在鍵盤上的狀態
SetLocaleInfo 改變用戶“地方”設置信息

SetLocalTime 設置當前地方時間
SetSysColors 設置指定窗口顯示對象的顏色
SetSystemCursor 改變任何一個標準系統指針
SetSystemTime 設置當前系統時間
SetSystemTimeAdjustment 定時添加一個校準值使內部系統時鐘與一個外部的時鐘信號源同步
SetThreadLocale 爲當前線程設置地方
SetTimeZoneInformation 設置系統時區信息
ShowCaret 在指定的窗口裏顯示插入符(光標)
ShowCursor 控制鼠標指針的可視性
SwapMouseButton 決定是否互換鼠標左右鍵的功能

SystemParametersInfo 獲取和設置數量衆多的windows系統參數
SystemTimeToTzSpecificLocalTime 將系統時間轉換成地方時間
ToAscii 根據當前的掃描碼和鍵盤信息,將一個虛擬鍵轉換成ASCII字符
ToUnicode 根據當前的掃描碼和鍵盤信息,將一個虛擬鍵轉換成Unicode字符
UnloadKeyboardLayout 卸載指定的鍵盤佈局
VkKeyScan 針對Windows字符集中一個ASCII字符,判斷虛擬鍵碼和Shift鍵的狀態


tsqgw (2002-03-14 14:50:00)
AppendMenu 在指定的菜單裏添加一個菜單項
CheckMenuItem 複選或撤消複選指定的菜單條目
CheckMenuRadioItem 指定一個菜單條目被複選成“單選”項目
CreateMenu 創建新菜單
CreatePopupMenu 創建一個空的彈出式菜單
DeleteMenu 刪除指定的菜單條目
DestroyMenu 刪除指定的菜單
DrawMenuBar 爲指定的窗口重畫菜單
EnableMenuItem 允許或禁止指定的菜單條目
GetMenu 取得窗口中一個菜單的句柄
GetMenuCheckMarkDimensions 返回一個菜單複選符的大小

GetMenuContextHelpId 取得一個菜單的幫助場景ID
GetMenuDefaultItem 判斷菜單中的哪個條目是默認條目
GetMenuItemCount 返回菜單中條目(菜單項)的數量
GetMenuItemID 返回位於菜單中指定位置處的條目的菜單ID
GetMenuItemInfo 取得(接收)與一個菜單條目有關的特定信息
GetMenuItemRect 在一個矩形中裝載指定菜單條目的屏幕座標信息
GetMenuState 取得與指定菜單條目狀態有關的信息
GetMenuString 取得指定菜單條目的字串
GetSubMenu 取得一個彈出式菜單的句柄,它位於菜單中指定的位置

GetSystemMenu 取得指定窗口的系統菜單的句柄
HiliteMenuItem 控制頂級菜單條目的加亮顯示狀態
InsertMenu 在菜單的指定位置處插入一個菜單條目,並根據需要將其他條目向下移動
InsertMenuItem 插入一個新菜單條目
IsMenu 判斷指定的句柄是否爲一個菜單的句柄
LoadMenu 從指定的模塊或應用程序實例中載入一個菜單
LoadMenuIndirect 載入一個菜單
MenuItemFromPoint 判斷哪個菜單條目包含了屏幕上一個指定的點
ModifyMenu 改變菜單條目

RemoveMenu 刪除指定的菜單條目
SetMenu 設置窗口菜單
SetMenuContextHelpId 設置一個菜單的幫助場景ID
SetMenuDefaultItem 將一個菜單條目設爲默認條目
SetMenuItemBitmaps 設置一幅特定位圖,令其在指定的菜單條目中使用,代替標準的複選符號(√)
SetMenuItemInfo 爲一個菜單條目設置指定的信息
TrackPopupMenu 在屏幕的任意地方顯示一個彈出式菜單
TrackPopupMenuEx 與TrackPopupMenu相似,只是它提供了額外的功能



以下是幾個關於菜單函數的類型定義
MENUITEMINFO 這個結構包含了菜單條目的信息
TPMPARAMS 這個結構用於TrackPopupMenuEx函數以支持額外的功能

tsqgw (2002-03-14 14:50:00)
AbortPath 拋棄選入指定設備場景中的所有路徑。也取消目前正在進行的任何路徑的創建工作
AngleArc 用一個連接弧畫一條線
Arc 畫一個圓弧
BeginPath 啓動一個路徑分支
CancelDC 取消另一個線程裏的長時間繪圖操作
Chord 畫一個弦
CloseEnhMetaFile 關閉指定的增強型圖元文件設備場景,並將新建的圖元文件返回一個句柄
CloseFigure 描繪到一個路徑時,關閉當前打開的圖形
CloseMetaFile 關閉指定的圖元文件設備場景,並向新建的圖元文件返回一個句柄

CopyEnhMetaFile 製作指定增強型圖元文件的一個副本(拷貝)
CopyMetaFile 製作指定(標準)圖元文件的一個副本
CreateBrushIndirect 在一個LOGBRUSH數據結構的基礎上創建一個刷子
CreateDIBPatternBrush 用一幅與設備無關的位圖創建一個刷子,以便指定刷子樣式(圖案)
CreateEnhMetaFile 創建一個增強型的圖元文件設備場景
CreateHatchBrush 創建帶有陰影圖案的一個刷子
CreateMetaFile 創建一個圖元文件設備場景
CreatePatternBrush 用指定了刷子圖案的一幅位圖創建一個刷子

CreatePen 用指定的樣式、寬度和顏色創建一個畫筆
CreatePenIndirect 根據指定的LOGPEN結構創建一個畫筆
CreateSolidBrush 用純色創建一個刷子
DeleteEnhMetaFile 刪除指定的增強型圖元文件
DeleteMetaFile 刪除指定的圖元文件
DeleteObject 刪除GDI對象,對象使用的所有系統資源都會被釋放
DrawEdge 用指定的樣式描繪一個矩形的邊框
DrawEscape 換碼(Escape)函數將數據直接發至顯示設備驅動程序
DrawFocusRect 畫一個焦點矩形

DrawFrameControl 描繪一個標準控件
DrawState 爲一幅圖象或繪圖操作應用各式各樣的效果
Ellipse 描繪一個橢圓,由指定的矩形圍繞
EndPath 停止定義一個路徑
EnumEnhMetaFile 針對一個增強型圖元文件,列舉其中單獨的圖元文件記錄
EnumMetaFile 爲一個標準的windows圖元文件枚舉單獨的圖元文件記錄
EnumObjects 枚舉可隨同指定設備場景使用的畫筆和刷子
ExtCreatePen 創建一個擴展畫筆(裝飾或幾何)
ExtFloodFill 在指定的設備場景裏,用當前選擇的刷子填充一個區域

FillPath 關閉路徑中任何打開的圖形,並用當前刷子填充
FillRect 用指定的刷子填充一個矩形
FlattenPath 將一個路徑中的所有曲線都轉換成線段
FloodFill 用當前選定的刷子在指定的設備場景中填充一個區域
FrameRect 用指定的刷子圍繞一個矩形畫一個邊框
GdiComment 爲指定的增強型圖元文件設備場景添加一條註釋信息
GdiFlush 執行任何未決的繪圖操作
GdiGetBatchLimit 判斷有多少個GDI繪圖命令位於隊列中
GdiSetBatchLimit 指定有多少個GDI繪圖命令能夠進入隊列

GetArcDirection 畫圓弧的時候,判斷當前採用的繪圖方向
GetBkColor 取得指定設備場景當前的背景顏色
GetBkMode 針對指定的設備場景,取得當前的背景填充模式
GetBrushOrgEx 判斷指定設備場景中當前選定刷子起點
GetCurrentObject 獲得指定類型的當前選定對象
GetCurrentPositionEx 在指定的設備場景中取得當前的畫筆位置
GetEnhMetaFile 取得磁盤文件中包含的一個增強型圖元文件的圖元文件句柄
GetEnhMetaFileBits 將指定的增強型圖元文件複製到一個內存緩衝區裏

GetEnhMetaFileDescription 返回對一個增強型圖元文件的說明
GetEnhMetaFileHeader 取得增強型圖元文件的圖元文件頭
GetEnhMetaFilePaletteEntries 取得增強型圖元文件的全部或部分調色板
GetMetaFile 取得包含在一個磁盤文件中的圖元文件的圖元文件句柄
GetMetaFileBitsEx 將指定的圖元文件複製到一個內存緩衝區
GetMiterLimit 取得設備場景的斜率限制(Miter)設置
GetNearestColor 根據設備的顯示能力,取得與指定顏色最接近的一種純色

GetObjectAPI 取得對指定對象進行說明的一個結構
GetObjectType 判斷由指定句柄引用的GDI對象的類型
GetPath 取得對當前路徑進行定義的一系列數據
GetPixel 在指定的設備場景中取得一個像素的RGB值
GetPolyFillMode 針對指定的設備場景,獲得多邊形填充模式
GetROP2 針對指定的設備場景,取得當前的繪圖模式
GetStockObject 取得一個固有對象(Stock)
GetSysColorBrush 爲任何一種標準系統顏色取得一個刷子
GetWinMetaFileBits 通過在一個緩衝區中填充用於標準圖元文件的數據,將一個增強型圖元文件轉換成標準windows圖元文件
InvertRect 通過反轉每個像素的值,從而反轉一個設備場景中指定的矩形
LineDDA 枚舉指定線段中的所有點
LineTo 用當前畫筆畫一條線,從當前位置連到一個指定的點

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章