sysutilh.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { Read date & Time function declarations }
  13. {$i osutilsh.inc}
  14. {$i datih.inc}
  15. { Read String Handling functions declaration }
  16. {$i sysstrh.inc}
  17. type
  18. { some helpful data types }
  19. {$IFDEF VER1_0}
  20. (* System type alias cannot be used under version *)
  21. (* 1.0 because of different names of System unit. *)
  22. THandle = longint;
  23. {$ELSE VER1_0}
  24. THandle = System.THandle;
  25. {$ENDIF VER1_0}
  26. tprocedure = procedure;
  27. tfilename = string;
  28. tintegerset = set of 0..sizeof(integer)*8-1;
  29. longrec = packed record
  30. case integer of
  31. 0 : (lo,hi : word);
  32. 1 : (bytes : array[0..3] of byte);
  33. end;
  34. wordrec = packed record
  35. lo,hi : byte;
  36. end;
  37. int64rec = packed record
  38. case integer of
  39. 0 : (lo,hi : cardinal);
  40. 1 : (words : array[0..3] of word);
  41. 2 : (bytes : array[0..7] of byte);
  42. end;
  43. pbytearray = ^tbytearray;
  44. tbytearray = array[0..32767] of byte;
  45. pwordarray = ^twordarray;
  46. twordarray = array[0..16383] of word;
  47. TMethod = packed record
  48. Code, Data: Pointer;
  49. end;
  50. { exceptions }
  51. Exception = class(TObject)
  52. private
  53. fmessage : string;
  54. fhelpcontext : longint;
  55. public
  56. constructor Create(const msg : string);
  57. constructor CreateFmt(const msg : string; const args : array of const);
  58. constructor CreateRes(ResString: PString);
  59. constructor CreateResFmt(ResString: PString; const Args: array of const);
  60. constructor CreateHelp(const Msg: string; AHelpContext: Integer);
  61. constructor CreateFmtHelp(const Msg: string; const Args: array of const;
  62. AHelpContext: Integer);
  63. constructor CreateResHelp(ResString: PString; AHelpContext: Integer);
  64. constructor CreateResFmtHelp(ResString: PString; const Args: array of const;
  65. AHelpContext: Integer);
  66. { !!!! }
  67. property helpcontext : longint read fhelpcontext write fhelpcontext;
  68. property message : string read fmessage write fmessage;
  69. end;
  70. ExceptClass = class of Exception;
  71. EExternal = class(Exception)
  72. public
  73. {$ifdef win32}
  74. ExceptionRecord : PExceptionRecord;
  75. {$endif win32}
  76. end;
  77. { integer math exceptions }
  78. EInterror = Class(EExternal);
  79. EDivByZero = Class(EIntError);
  80. ERangeError = Class(EIntError);
  81. EIntOverflow = Class(EIntError);
  82. { General math errors }
  83. EMathError = Class(EExternal);
  84. EInvalidOp = Class(EMathError);
  85. EZeroDivide = Class(EMathError);
  86. EOverflow = Class(EMathError);
  87. EUnderflow = Class(EMathError);
  88. { Run-time and I/O Errors }
  89. EInOutError = class(Exception)
  90. public
  91. ErrorCode : Longint;
  92. end;
  93. EHeapMemoryError = class(Exception)
  94. protected
  95. AllowFree : boolean;
  96. procedure FreeInstance;override;
  97. end;
  98. EHeapException = EHeapMemoryError;
  99. EExternalException = class(EExternal);
  100. EInvalidPointer = Class(EHeapMemoryError);
  101. EOutOfMemory = Class(EHeapMemoryError);
  102. EInvalidCast = Class(Exception);
  103. EVariantError = Class(Exception);
  104. EAccessViolation = Class(EExternal);
  105. EPrivilege = class(EExternal);
  106. EStackOverflow = class(EExternal);
  107. EControlC = class(EExternal);
  108. { String conversion errors }
  109. EConvertError = class(Exception);
  110. { Other errors }
  111. EAbort = Class(Exception);
  112. EAbstractError = Class(Exception);
  113. EAssertionFailed = Class(Exception);
  114. EPropReadOnly = class(Exception);
  115. EPropWriteOnly = class(Exception);
  116. EIntfCastError = class(Exception);
  117. EInvalidContainer = class(Exception);
  118. EInvalidInsert = class(Exception);
  119. EPackageError = class(Exception);
  120. ESafecallException = class(Exception);
  121. ENoThreadSupport = Class(Exception);
  122. { Exception handling routines }
  123. function ExceptObject: TObject;
  124. function ExceptAddr: Pointer;
  125. function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
  126. Buffer: PChar; Size: Integer): Integer;
  127. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  128. procedure Abort;
  129. procedure OutOfMemoryError;
  130. procedure Beep;
  131. function SysErrorMessage(ErrorCode: Integer): String;
  132. type
  133. TTerminateProc = function: Boolean;
  134. procedure AddTerminateProc(TermProc: TTerminateProc);
  135. function CallTerminateProcs: Boolean;
  136. Var
  137. OnShowException : Procedure (Msg : ShortString);
  138. { FileRec/TextRec }
  139. {$i filerec.inc}
  140. {$i textrec.inc}
  141. Const
  142. HexDisplayPrefix : string = '$';
  143. const
  144. // commenting is VP fix. These idents are in a different unit there.
  145. PathDelim={System.}DirectorySeparator;
  146. DriveDelim={System.}DriveSeparator;
  147. PathSep={System.}PathSeparator;
  148. Type
  149. TFileRec=FileRec;
  150. TTextRec=TextRec;
  151. { Read internationalization settings }
  152. {$i sysinth.inc}
  153. { Read pchar handling functions declaration }
  154. {$IFNDEF VIRTUALPASCAL}
  155. {$i syspchh.inc}
  156. {$ENDIF}
  157. { MCBS functions }
  158. {$i sysansih.inc}
  159. { Read filename handling functions declaration }
  160. {$i finah.inc}
  161. { Read other file handling function declarations }
  162. {$i filutilh.inc}
  163. { Read disk function declarations }
  164. {$i diskh.inc}
  165. { read thread handling }
  166. {$i systhrdh.inc}
  167. procedure FreeAndNil(var obj);
  168. {$ifdef HASINTF}
  169. { interface handling }
  170. {$i intfh.inc}
  171. {$endif HASINTF}
  172. {
  173. $Log$
  174. Revision 1.5 2003-11-26 22:17:42 michael
  175. + Merged fixbranch fixes, missing in main branch
  176. Revision 1.4 2003/11/26 20:12:08 michael
  177. + New runerror 231 (exception stack error) and 232 (nothread support)
  178. Revision 1.3 2003/11/26 20:00:19 florian
  179. * error handling for Variants improved
  180. Revision 1.2 2003/10/25 23:43:59 hajny
  181. * THandle in sysutils common using System.THandle
  182. Revision 1.1 2003/10/06 21:01:06 peter
  183. * moved classes unit to rtl
  184. Revision 1.20 2003/09/06 20:49:54 marco
  185. * Two minimal VP fixes
  186. Revision 1.19 2003/01/01 20:58:07 florian
  187. + added invalid instruction exception
  188. Revision 1.18 2002/10/07 19:43:24 florian
  189. + empty prototypes for the AnsiStr* multi byte functions added
  190. Revision 1.17 2002/09/07 16:01:22 peter
  191. * old logs removed and tabs fixed
  192. Revision 1.16 2002/01/25 17:42:03 peter
  193. * interface helpers
  194. }