首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

Delphi SysUtils 單元核心函數完整參考手冊

     編輯:Delphi

SysUtils 是 Delphi 基礎運行庫中最核心的單元之一,提供了字串處理、日期時間、檔案操作、記憶體管理、轉換函數、異常處理等數百個常用函數與過程。本文將這些函數按功能分類整理,方便開發者快速查找與學習。

主要功能分類

1. 字串處理與比較

  • 大小寫轉換:AnsiLowerCase、AnsiUpperCase、LowerCase、UpperCase、AnsiLowerCaseFileName、AnsiUpperCaseFileName
  • 比較與查找:AnsiCompareStr、AnsiCompareText、AnsiSameStr、AnsiSameText、AnsiPos、AnsiStrPos、CompareStr、CompareText、SameStr、SameText
  • 引號與分隔:AnsiQuotedStr、AnsiExtractQuotedStr、AnsiDequotedStr、QuotedStr、ExtractFileName、ExtractFilePath、ExtractFileExt、ExtractFileDir、ExtractFileDrive
  • 修剪與替換:Trim、TrimLeft、TrimRight、StringReplace、WrapText、AdjustLineBreaks

2. 日期時間與格式化

  • 當前時間:Now、Date、Time、GetTime
  • 編碼/解碼:EncodeDate、EncodeTime、DecodeDate、DecodeTime、DecodeDateFully、TryEncodeDate、TryEncodeTime
  • 格式化輸出:DateToStr、TimeToStr、DateTimeToStr、FormatDateTime、FormatFloat、FormatCurr、FloatToStr、FloatToStrF、CurrToStr、CurrToStrF
  • 轉換與計算:IncMonth、IncAMonth、DayOfWeek、CurrentYear、DateTimeToFileDate、FileDateToDateTime、DateTimeToSystemTime、SystemTimeToDateTime、DateTimeToTimeStamp、TimeStampToDateTime、MSecsToTimeStamp、TimeStampToMSecs、ReplaceDate、ReplaceTime

3. 檔案與目錄操作

  • 存在性檢查:FileExists、DirectoryExists、FileIsReadOnly
  • 屬性與時間:FileGetAttr、FileSetAttr、FileGetDate、FileSetDate、FileAge、FileSetReadOnly
  • 讀寫與流:FileOpen、FileCreate、FileRead、FileWrite、FileSeek、FileClose
  • 目錄管理:CreateDir、RemoveDir、ForceDirectories、GetCurrentDir、SetCurrentDir、ExtractRelativePath、ExpandFileName、ExpandUNCFileName、ExtractShortPathName
  • 搜尋:FindFirst、FindNext、FindClose、FileSearch

4. 型別轉換與工具函數

  • 字串轉數值:StrToInt、StrToIntDef、StrToInt64、StrToInt64Def、StrToFloat、StrToFloatDef、StrToCurr、StrToCurrDef、StrToBool、StrToBoolDef、StrToDate、StrToDateDef、StrToTime、StrToTimeDef、StrToDateTime、StrToDateTimeDef
  • 數值轉字串:IntToStr、IntToHex、UIntToStr、FloatToStr、BoolToStr
  • 記憶體與指標:GetMem、FreeMem、ReallocMem、AllocMem、CompareMem、StrAlloc、StrDispose、StrNew、StrPas、StrPCopy、StrPLCopy
  • GUID 與 COM:CreateGUID、GUIDToString、StringToGUID、IsEqualGUID、Supports

5. 異常、錯誤與系統資訊

  • 異常處理:ShowException、ExceptionErrorMessage、RaiseLastOSError、RaiseLastWin32Error、OutOfMemoryError
  • 系統錯誤訊息:SysErrorMessage、Win32Check
  • 版本與環境:CheckWin32Version、GetEnvironmentVariable、GetModuleName、GetPackageInfo、GetPackageDescription

6. 多國語言與字符集支援

  • Ansi/Unicode 字串:AnsiStrAlloc、AnsiStrComp、AnsiStrLComp、AnsiStrLIComp、AnsiStrUpper、AnsiStrLower、WideUpperCase、WideLowerCase、WideCompareStr、WideCompareText、WideSameStr、WideSameText、WideFormat、WideFormatBuf、WideFmtStr
  • 字元/位元組索引轉換:ByteToCharIndex、ByteToCharLen、CharToByteIndex、CharToByteLen、CharLength、CharInSet、ElementToCharIndex、ElementToCharLen、CharToElementIndex、CharToElementLen

7. 封裝與動態載入

  • LoadPackage、UnloadPackage、InitializePackage、FinalizePackage、GetPackageInfo、GetPackageDescription、SafeLoadLibrary

8. 其他實用函數

  • Abort、Beep、Sleep、Randomize(實際在 System)、FreeAndNil、Format、FmtStr、FmtLoadStr、LoadStr、FindCmdLineSwitch、GetFormatSettings、GetLocaleFormatSettings、GetLocaleStr、GetLocaleChar

使用建議

  1. 預設開啟:新建 VCL/FMX 專案時,SysUtils 已自動加入 uses,可直接使用。
  2. 配合 DateUtils:進階日期計算(如 IsInLeapYear、WeekOf、DaysBetween)需額外引用 DateUtils。
  3. 避免重複造輪子:檔案路徑操作、字串格式化、型別轉換等高頻需求,優先檢查 SysUtils 是否已提供現成函數。
  4. 異常安全:使用 FreeAndNil 釋放物件,配合 try..finally 確保資源釋放。

快速查找技巧

在 IDE 編輯器中按 Ctrl+Space 輸入 SysUtils. 即可列出所有公開符號;或將游標放在函數名上按 F1 打開線上幫助查看詳細參數說明。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved