前言
本文彙整了Borland C++ Builder (BCB) 與 Delphi 開發中最常用的核心單元函數與過程,按功能模組分類整理,供開發者快速查閱。內容涵蓋動作列表、核心類別、剪貼簿、控制項、資料庫、對話框、圖形繪製、數學運算、選單、OLE、列印、系統底層與字串處理等關鍵領域。
ActnList 單元:動作管理
- CreateAction:建立指定類型的動作,並顯示於動作列表編輯器中。
- EnumRegisteredActions:列舉已註冊的動作。
- RegisterAction / UnRegisterAction:註冊與反註冊動作。
Classes 單元:核心類別與串流操作
幾何結構
- Point(X, Y):回傳
TPoint 結構。
- Rect(Left, Top, Right, Bottom) / Bounds(Top, Left, Width, Height):回傳
TRect 矩形結構。
類別註冊與串流轉換
- RegisterClass / RegisterClasses:註冊
TPersistent 衍生類別,使其型別可被識別(元件儲存/載入必備)。
- RegisterClassAlias:為同一類別註冊別名。
- UnregisterClass / UnregisterClasses:反註冊類別。
- FindClass / GetClass:由字串取得已註冊的類別參考。
- ObjectBinaryToText / ObjectTextToBinary、ObjectResourceToText / ObjectTextToResource:物件二進位/文字/資源格式互轉。
- ReadComponentRes / ReadComponentResFile / WriteComponentResFile:從資源讀寫元件及其屬性。
工具函數
- CollectionsEqual:比較兩個
TCollection 是否相等。
- LineStart:取得下一行起始字元位置。
- RegisterComponents / RegisterNoIcon / RegisterNonActiveX:元件面板註冊相關。
Clipbrd 單元:剪貼簿
- Clipboard:取得全域
TClipboard 物件。
- SetClipboard:替換全域剪貼簿物件。
Controls 單元:控制項核心
- FindControl(Handle):由視窗控制代碼取得
TWinControl 實例。
- FindDragTarget / FindVCLWindow:尋找滑鼠下的拖放目標或 VCL 控制項。
- GetCaptureControl / SetCaptureControl:取得/設定捕捉滑鼠事件的控制項。
- GetShortHint / GetLongHint:分割 Hint 字串(以
| 分隔)。
- CursorToIdent / IdentToCursor / StringToCursor / CursorToString:游標常數與字串互轉。
- CancelDrag / MoveWindowOrg / IsDragObject:拖放與座標轉換輔助。
Db / Dbctrls / Dblogdlg / Dbpwdlg / Dbtables 單元:資料庫核心
- BCDToCurr / VarTypeToDataType:資料型別轉換。
- DatabaseError / DatabaseErrorFmt / DBIError:建立並觸發資料庫例外。
- RegisterFields:註冊欄位類別。
- LoginDialog / LoginDialogEx / RemoteLoginDialog:登入對話框。
- AnsiToNative / NativeToAnsi 等:ANSI 與本地字集互轉。
- NativeCompareStr / NativeCompareText:依本地資料庫規則比較字串。
- Session / Sessions:全域
TSession 與 TSessionList。
Dialogs 單元:標準對話框
- MessageDlg / MessageDlgPos / MessageDlgPosHelp:訊息方塊(可指定位置與說明)。
- ShowMessage / ShowMessageFmt:簡易訊息方塊。
- InputBox / InputQuery:輸入方塊(後者有回傳值判斷確認/取消)。
- CreateMessageDialog:建立自訂訊息對話框實例。
- ForceCurrentDirectory:控制初始目錄為目前路徑或「我的文件」。
Drintf 單元:資料字典介面
提供屬性、欄位、資料表、資料庫的 ID 查詢與關聯管理,以及約束條件、資料集同步更新功能(UpdateDataset、UpdateField 等)。
DsgnIntf / Exptintf 單元:設計時介面與專家註冊
- RegisterPropertyEditor / RegisterComponentEditor:註冊屬性/元件編輯器。
- RegisterPropertyInCategory / RegisterPropertiesInCategory:屬性分類註冊(物件檢視器分類)。
- RegisterLibraryExpert:註冊 IDE 專家。
ExtCtrls / FileCtrl / Forms 單元
- Frame3D:賦予控制項 3D 外觀。
- DirectoryExists / ForceDirectories / SelectDirectory / ProcessPath:目錄操作與選擇對話框。
- Application / Screen:全域應用程式與螢幕資訊物件。
- GetParentForm / ValidParentForm:取得包含指定控制項的表單。
- HintWindowClass / IsAccel:提示視窗類別參考、加速鍵判斷。
Graphics 單元:圖形與色彩
- ColorToRGB / ColorToIdent / IdentToColor / StringToColor / ColorToString:色彩與字串/常數互轉。
- CharsetToIdent / IdentToCharset / GetDefFontCharset:字元集處理。
- GetDIB / GetDIBSizes / CreateMappedBmp / CreateGrayMappedBmp:裝置無關位圖 (DIB) 與色彩映射操作。
- GraphicExtension / GraphicFileMask / GraphicFilter:圖檔副檔名、遮罩、過濾器字串。
- CopyPalette / SystemPalette16 / DDBsOnly:調色板與裝置相關位圖標誌。
Mask / Math 單元
- FormatMaskText:格式化編輯遮罩文字。
- 數學函數完整涵蓋:三角/雙曲函數(
ArcCos、Sinh 等)、角度轉換(DegToRad、CycleToRad)、對數/指數(LogN、Power)、統計(Mean、StdDev、SumOfSquares)、財務(Payment、NetPresentValue)、多項式(Poly)、隨機數(RandG)等。
Menus 單元:選單操作
- NewMenu / NewPopupMenu / NewItem / NewLine / NewSubMenu:動態建立選單項目。
- ShortCut / ShortCutToText / TextToShortCut / ShortCutToKey:快捷鍵建立與轉換。
- AnsiSameCaption / StripHotKey:忽略大小寫與熱鍵比較、移除加速鍵字元。
- PopupList:應用程式中所有彈出式選單清單。
OleCtrls / OleCtnrs / Printers 單元
- FontToOleFont / OleFontToFont:VCL 字型與 OLE 字型互轉。
- DestroyMetaPict:釋放中繼檔圖片資源。
- Printer / AssignPrn:全域列印機物件、指派文字檔給列印機。
System 單元:語言核心與底層操作
包含記憶體管理(GetMem/FreeMem/ReallocMem、AllocMemCount/Size)、檔案 I/O(AssignFile/Reset/Rewrite/BlockRead/Write)、字串操作(Copy/Delete/Insert/Pos/Length/Concat)、數學(Abs/Sqr/Sqrt/Sin/Cos/Exp/Ln)、型別轉換(IntToStr/StrToInt/FloatToStr/StrToFloat)、變體操作(VarArrayCreate/VarAsType/VarIsEmpty/VarToStr)、Unicode 轉換(WideCharToString/StringToWideChar)、程式控制(Exit/Halt/Break/Continue)、模組枚舉、執行緒變數等核心功能。
SysUtils 單元:系統工具進階
字串處理強化
- ANSI 感知比較:
AnsiCompareStr/Text、AnsiSameStr/Text、AnsiStrComp/IComp/LComp。
- 大小寫轉換:
AnsiUpperCase/LowerCase、AnsiUpperCaseFileName。
- 路徑操作:
ExtractFilePath/Dir/Drive/Name/Ext、ExpandFileName/UNCFileName、ExtractRelativePath/ShortPathName、Include/ExcludeTrailingBackslash、ChangeFileExt。
- 格式化:
Format/FormatFloat/FormatCurr/FormatDateTime/FmtStr。
- 轉換:
IntToHex/StrToInt64/StrToFloat/StrToDateTime/CurrToStr 等。
日期時間
Date/Time/Now、DateTimeToStr/DateToStr/TimeToStr、EncodeDate/Time、DecodeDate/Time、IncMonth/IsLeapYear/DayOfWeek、DateTimeToFileDate/SystemTime/TimeStamp 互轉。
檔案與目錄
FileExists/Age/Size/Date、FileOpen/Close/Read/Write/Seek、FileGet/SetAttr/Date、FindFirst/Next/Close、CreateDir/RemoveDir/DeleteFile/RenameFile、DiskFree/Size。
例外與錯誤處理
Abort/ShowException/RaiseLastWin32Error/ExceptionErrorMessage、ExceptAddr/ExceptObject、Win32Check。
記憶體與封裝
GetMem/FreeMem/ReallocMem/AllocMem、SetMemoryManager/GetMemoryManager/IsMemoryManagerSet。
- 套件管理:
LoadPackage/UnloadPackage/GetPackageInfo/Description、InitializePackage/FinalizePackage。
其他實用函數
WrapText/Trim/TrimLeft/TrimRight、StringReplace/QuotedStr/AnsiExtractQuotedStr、Supports(介面查詢)、SysErrorMessage、Languages、SafeLoadLibrary、BeginThread/EndThread。