sysutilh.inc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. member of the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { Using inlining for small system functions/wrappers }
  12. {$inline on}
  13. {$define SYSUTILSINLINE}
  14. { Read internationalization settings }
  15. {$i sysinth.inc}
  16. { Read date & Time function declarations }
  17. {$i osutilsh.inc}
  18. {$ifndef FPUNONE}
  19. {$i datih.inc}
  20. {$endif}
  21. { Read String Handling functions declaration }
  22. {$i sysstrh.inc}
  23. type
  24. { some helpful data types }
  25. THandle = System.THandle;
  26. TProcedure = procedure;
  27. TFilename = String;
  28. TIntegerSet = Set of 0..SizeOf(Integer)*8-1;
  29. LongRec = packed record
  30. case Integer of
  31. {$ifdef FPC_LITTLE_ENDIAN}
  32. 0 : (Lo,Hi : Word);
  33. {$else FPC_LITTLE_ENDIAN}
  34. 0 : (Hi,Lo : Word);
  35. {$endif FPC_LITTLE_ENDIAN}
  36. 1 : (Bytes : Array[0..3] of Byte);
  37. end;
  38. WordRec = packed record
  39. {$ifdef FPC_LITTLE_ENDIAN}
  40. Lo,Hi : Byte;
  41. {$else FPC_LITTLE_ENDIAN}
  42. Hi,Lo : Byte;
  43. {$endif FPC_LITTLE_ENDIAN}
  44. end;
  45. Int64Rec = packed record
  46. case integer of
  47. {$ifdef FPC_LITTLE_ENDIAN}
  48. 0 : (Lo,Hi : Cardinal);
  49. {$else FPC_LITTLE_ENDIAN}
  50. 0 : (Hi,Lo : Cardinal);
  51. {$endif FPC_LITTLE_ENDIAN}
  52. 1 : (Words : Array[0..3] of Word);
  53. 2 : (Bytes : Array[0..7] of Byte);
  54. end;
  55. Int128Rec = packed record
  56. case integer of
  57. {$ifdef FPC_LITTLE_ENDIAN}
  58. 0 : (Lo,Hi : QWord);
  59. {$else FPC_LITTLE_ENDIAN}
  60. 0 : (Hi,Lo : QWord);
  61. {$endif FPC_LITTLE_ENDIAN}
  62. 1 : (DWords : Array[0..3] of DWord);
  63. 2 : (Words : Array[0..7] of Word);
  64. 3 : (Bytes : Array[0..15] of Byte);
  65. end;
  66. OWordRec = packed record
  67. case integer of
  68. {$ifdef FPC_LITTLE_ENDIAN}
  69. 0 : (Lo,Hi : QWord);
  70. {$else FPC_LITTLE_ENDIAN}
  71. 0 : (Hi,Lo : QWord);
  72. {$endif FPC_LITTLE_ENDIAN}
  73. 1 : (DWords : Array[0..3] of DWord);
  74. 2 : (Words : Array[0..7] of Word);
  75. 3 : (Bytes : Array[0..15] of Byte);
  76. end;
  77. PByteArray = ^TByteArray;
  78. TByteArray = Array[0..32767] of Byte;
  79. PWordarray = ^TWordArray;
  80. TWordArray = array[0..16383] of Word;
  81. { exceptions }
  82. Exception = class(TObject)
  83. private
  84. fmessage : string;
  85. fhelpcontext : longint;
  86. public
  87. constructor Create(const msg : string);
  88. constructor CreateFmt(const msg : string; const args : array of const);
  89. constructor CreateRes(ResString: PString);
  90. constructor CreateResFmt(ResString: PString; const Args: array of const);
  91. constructor CreateHelp(const Msg: string; AHelpContext: Integer);
  92. constructor CreateFmtHelp(const Msg: string; const Args: array of const;
  93. AHelpContext: Integer);
  94. constructor CreateResHelp(ResString: PString; AHelpContext: Integer);
  95. constructor CreateResFmtHelp(ResString: PString; const Args: array of const;
  96. AHelpContext: Integer);
  97. { !!!! }
  98. property HelpContext : longint read fhelpcontext write fhelpcontext;
  99. property Message : string read fmessage write fmessage;
  100. end;
  101. ExceptClass = class of Exception;
  102. EExternal = class(Exception)
  103. public
  104. {$ifdef win32}
  105. ExceptionRecord : PExceptionRecord;
  106. {$endif win32}
  107. end;
  108. { integer math exceptions }
  109. EInterror = Class(EExternal);
  110. EDivByZero = Class(EIntError);
  111. ERangeError = Class(EIntError);
  112. EIntOverflow = Class(EIntError);
  113. { General math errors }
  114. EMathError = Class(EExternal);
  115. EInvalidOp = Class(EMathError);
  116. EZeroDivide = Class(EMathError);
  117. EOverflow = Class(EMathError);
  118. EUnderflow = Class(EMathError);
  119. { Run-time and I/O Errors }
  120. EInOutError = class(Exception)
  121. public
  122. ErrorCode : Longint;
  123. end;
  124. EHeapMemoryError = class(Exception)
  125. protected
  126. AllowFree : boolean;
  127. public
  128. procedure FreeInstance;override;
  129. end;
  130. EHeapException = EHeapMemoryError;
  131. EExternalException = class(EExternal);
  132. EInvalidPointer = Class(EHeapMemoryError);
  133. EOutOfMemory = Class(EHeapMemoryError);
  134. EInvalidCast = Class(Exception);
  135. EVariantError = Class(Exception)
  136. ErrCode : longint;
  137. Constructor CreateCode(Code : Longint);
  138. end;
  139. EAccessViolation = Class(EExternal);
  140. EBusError = Class(EAccessViolation);
  141. EPrivilege = class(EExternal);
  142. EStackOverflow = class(EExternal);
  143. EControlC = class(EExternal);
  144. { String conversion errors }
  145. EConvertError = class(Exception);
  146. EFormatError = class(Exception);
  147. { Other errors }
  148. EAbort = Class(Exception);
  149. EAbstractError = Class(Exception);
  150. EAssertionFailed = Class(Exception);
  151. EPropReadOnly = class(Exception);
  152. EPropWriteOnly = class(Exception);
  153. EIntfCastError = class(Exception);
  154. EInvalidContainer = class(Exception);
  155. EInvalidInsert = class(Exception);
  156. EPackageError = class(Exception);
  157. EOSError = class(Exception)
  158. public
  159. ErrorCode: Longint;
  160. end;
  161. ESafecallException = class(Exception);
  162. ENoThreadSupport = Class(Exception);
  163. ENoWideStringSupport = Class(Exception);
  164. ENotImplemented = class(Exception);
  165. { Exception handling routines }
  166. function ExceptObject: TObject;
  167. function ExceptAddr: Pointer;
  168. function ExceptFrameCount: Longint;
  169. function ExceptFrames: PPointer;
  170. function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
  171. Buffer: PChar; Size: Integer): Integer;
  172. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  173. procedure Abort;
  174. procedure OutOfMemoryError;
  175. Type
  176. TBeepHandler = Procedure;
  177. Var
  178. OnBeep : TBeephandler = Nil;
  179. procedure Beep;
  180. function SysErrorMessage(ErrorCode: Integer): String;
  181. Type
  182. TCreateGUIDFunc = Function(Out GUID : TGUID) : Integer;
  183. Var
  184. OnCreateGUID : TCreateGUIDFunc = Nil;
  185. Function CreateGUID(out GUID : TGUID) : Integer;
  186. type
  187. TTerminateProc = Function: Boolean;
  188. procedure AddTerminateProc(TermProc: TTerminateProc);
  189. function CallTerminateProcs: Boolean;
  190. Var
  191. OnShowException : Procedure (Msg : ShortString);
  192. { FileRec/TextRec }
  193. {$i filerec.inc}
  194. {$i textrec.inc}
  195. Const
  196. HexDisplayPrefix : string = '$';
  197. const
  198. // commenting is VP fix. These idents are in a different unit there.
  199. PathDelim={System.}DirectorySeparator;
  200. DriveDelim={System.}DriveSeparator;
  201. PathSep={System.}PathSeparator;
  202. MAX_PATH={System.}MaxPathLen;
  203. Type
  204. TFileRec=FileRec;
  205. TTextRec=TextRec;
  206. { Read pchar handling functions declaration }
  207. {$i syspchh.inc}
  208. { MCBS functions }
  209. {$i sysansih.inc}
  210. { wide string functions }
  211. {$i syswideh.inc}
  212. {$ifdef FPC_HAS_UNICODESTRING}
  213. { unicode string functions }
  214. {$i sysunih.inc}
  215. {$endif FPC_HAS_UNICODESTRING}
  216. { Read filename handling functions declaration }
  217. {$i finah.inc}
  218. { Read other file handling function declarations }
  219. {$i filutilh.inc}
  220. { Read disk function declarations }
  221. {$i diskh.inc}
  222. { read thread handling }
  223. {$i systhrdh.inc}
  224. procedure FreeAndNil(var obj);
  225. { interface handling }
  226. {$i intfh.inc}
  227. function SafeLoadLibrary(const FileName: AnsiString;
  228. ErrorMode: DWord = {$ifdef windows}SEM_NOOPENFILEERRORBOX{$else windows}0{$endif windows}): HMODULE;
  229. function GetModuleName(Module: HMODULE): string;
  230. { some packages and unit related constants for compatibility }
  231. const
  232. pfExeModule = $00000000;
  233. pfNeverBuild = $00000001;
  234. pfDesignOnly = $00000002;
  235. pfRunOnly = $00000004;
  236. pfIgnoreDupUnits = $00000008;
  237. pfPackageModule = $40000000;
  238. pfModuleTypeMask = $C0000000;
  239. pfV3Produced = $00000000;
  240. pfProducerUndefined = $04000000;
  241. pfBCB4Produced = $08000000;
  242. pfDelphi4Produced = $0C000000;
  243. pfLibraryModule = $80000000;
  244. pfProducerMask = $0C000000;
  245. const
  246. ufMainUnit = $01;
  247. ufPackageUnit = $02;
  248. ufWeakUnit = $04;
  249. ufOrgWeakUnit = $08;
  250. ufImplicitUnit = $10;
  251. ufWeakPackageUnit = ufPackageUnit or ufWeakUnit;