sysutilh.inc 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. TBytes = array of Byte;
  82. { exceptions }
  83. Exception = class(TObject)
  84. private
  85. fmessage : string;
  86. fhelpcontext : longint;
  87. public
  88. constructor Create(const msg : string);
  89. constructor CreateFmt(const msg : string; const args : array of const);
  90. constructor CreateRes(ResString: PString);
  91. constructor CreateResFmt(ResString: PString; const Args: array of const);
  92. constructor CreateHelp(const Msg: string; AHelpContext: Integer);
  93. constructor CreateFmtHelp(const Msg: string; const Args: array of const;
  94. AHelpContext: Integer);
  95. constructor CreateResHelp(ResString: PString; AHelpContext: Integer);
  96. constructor CreateResFmtHelp(ResString: PString; const Args: array of const;
  97. AHelpContext: Integer);
  98. { !!!! }
  99. property HelpContext : longint read fhelpcontext write fhelpcontext;
  100. property Message : string read fmessage write fmessage;
  101. end;
  102. ExceptClass = class of Exception;
  103. EExternal = class(Exception)
  104. public
  105. {$ifdef win32}
  106. ExceptionRecord : PExceptionRecord;
  107. {$endif win32}
  108. end;
  109. { integer math exceptions }
  110. EInterror = Class(EExternal);
  111. EDivByZero = Class(EIntError);
  112. ERangeError = Class(EIntError);
  113. EIntOverflow = Class(EIntError);
  114. { General math errors }
  115. EMathError = Class(EExternal);
  116. EInvalidOp = Class(EMathError);
  117. EZeroDivide = Class(EMathError);
  118. EOverflow = Class(EMathError);
  119. EUnderflow = Class(EMathError);
  120. { Run-time and I/O Errors }
  121. EInOutError = class(Exception)
  122. public
  123. ErrorCode : Longint;
  124. end;
  125. EHeapMemoryError = class(Exception)
  126. protected
  127. AllowFree : boolean;
  128. public
  129. procedure FreeInstance;override;
  130. end;
  131. EHeapException = EHeapMemoryError;
  132. EExternalException = class(EExternal);
  133. EInvalidPointer = Class(EHeapMemoryError);
  134. EOutOfMemory = Class(EHeapMemoryError);
  135. EInvalidCast = Class(Exception);
  136. EVariantError = Class(Exception)
  137. ErrCode : longint;
  138. Constructor CreateCode(Code : Longint);
  139. end;
  140. EAccessViolation = Class(EExternal);
  141. EBusError = Class(EAccessViolation);
  142. EPrivilege = class(EExternal);
  143. EStackOverflow = class(EExternal);
  144. EControlC = class(EExternal);
  145. { String conversion errors }
  146. EConvertError = class(Exception);
  147. EFormatError = class(Exception);
  148. { Other errors }
  149. EAbort = Class(Exception);
  150. EAbstractError = Class(Exception);
  151. EAssertionFailed = Class(Exception);
  152. EPropReadOnly = class(Exception);
  153. EPropWriteOnly = class(Exception);
  154. EIntfCastError = class(Exception);
  155. EInvalidContainer = class(Exception);
  156. EInvalidInsert = class(Exception);
  157. EPackageError = class(Exception);
  158. EOSError = class(Exception)
  159. public
  160. ErrorCode: Longint;
  161. end;
  162. ESafecallException = class(Exception);
  163. ENoThreadSupport = Class(Exception);
  164. ENoWideStringSupport = Class(Exception);
  165. ENotImplemented = class(Exception);
  166. EArgumentException = class(Exception);
  167. EArgumentOutOfRangeException = class(EArgumentException);
  168. { Exception handling routines }
  169. function ExceptObject: TObject;
  170. function ExceptAddr: Pointer;
  171. function ExceptFrameCount: Longint;
  172. function ExceptFrames: PPointer;
  173. function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
  174. Buffer: PChar; Size: Integer): Integer;
  175. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  176. procedure Abort;
  177. procedure OutOfMemoryError;
  178. Type
  179. TBeepHandler = Procedure;
  180. Var
  181. OnBeep : TBeephandler = Nil;
  182. procedure Beep;
  183. function SysErrorMessage(ErrorCode: Integer): String;
  184. Type
  185. TCreateGUIDFunc = Function(Out GUID : TGUID) : Integer;
  186. Var
  187. OnCreateGUID : TCreateGUIDFunc = Nil;
  188. Function CreateGUID(out GUID : TGUID) : Integer;
  189. type
  190. TTerminateProc = Function: Boolean;
  191. procedure AddTerminateProc(TermProc: TTerminateProc);
  192. function CallTerminateProcs: Boolean;
  193. Var
  194. OnShowException : Procedure (Msg : ShortString);
  195. { FileRec/TextRec }
  196. {$i filerec.inc}
  197. {$i textrec.inc}
  198. Const
  199. HexDisplayPrefix : string = '$';
  200. const
  201. // commenting is VP fix. These idents are in a different unit there.
  202. PathDelim={System.}DirectorySeparator;
  203. DriveDelim={System.}DriveSeparator;
  204. PathSep={System.}PathSeparator;
  205. MAX_PATH={System.}MaxPathLen;
  206. Type
  207. TFileRec=FileRec;
  208. TTextRec=TextRec;
  209. { Read pchar handling functions declaration }
  210. {$i syspchh.inc}
  211. { MCBS functions }
  212. {$i sysansih.inc}
  213. { wide string functions }
  214. {$i syswideh.inc}
  215. {$ifdef FPC_HAS_UNICODESTRING}
  216. { unicode string functions }
  217. {$i sysunih.inc}
  218. {$endif FPC_HAS_UNICODESTRING}
  219. { Read filename handling functions declaration }
  220. {$i finah.inc}
  221. { Read other file handling function declarations }
  222. {$i filutilh.inc}
  223. { Read disk function declarations }
  224. {$i diskh.inc}
  225. { read thread handling }
  226. {$i systhrdh.inc}
  227. procedure FreeAndNil(var obj);
  228. { interface handling }
  229. {$i intfh.inc}
  230. function SafeLoadLibrary(const FileName: AnsiString;
  231. ErrorMode: DWord = {$ifdef windows}SEM_NOOPENFILEERRORBOX{$else windows}0{$endif windows}): HMODULE;
  232. function GetModuleName(Module: HMODULE): string;
  233. { some packages and unit related constants for compatibility }
  234. const
  235. pfExeModule = $00000000;
  236. pfNeverBuild = $00000001;
  237. pfDesignOnly = $00000002;
  238. pfRunOnly = $00000004;
  239. pfIgnoreDupUnits = $00000008;
  240. pfPackageModule = $40000000;
  241. pfModuleTypeMask = $C0000000;
  242. pfV3Produced = $00000000;
  243. pfProducerUndefined = $04000000;
  244. pfBCB4Produced = $08000000;
  245. pfDelphi4Produced = $0C000000;
  246. pfLibraryModule = $80000000;
  247. pfProducerMask = $0C000000;
  248. const
  249. ufMainUnit = $01;
  250. ufPackageUnit = $02;
  251. ufWeakUnit = $04;
  252. ufOrgWeakUnit = $08;
  253. ufImplicitUnit = $10;
  254. ufWeakPackageUnit = ufPackageUnit or ufWeakUnit;