objpash.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. This unit makes Free Pascal as much as possible Delphi compatible
  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. {*****************************************************************************
  13. Basic Types/constants
  14. *****************************************************************************}
  15. const
  16. vmtInstanceSize = 0;
  17. vmtParent = sizeof(ptrint)*2;
  18. { These were negative value's, but are now positive, else classes
  19. couldn't be used with shared linking which copies only all data from
  20. the .global directive and not the data before the directive (PFV) }
  21. vmtClassName = vmtParent+sizeof(pointer);
  22. vmtDynamicTable = vmtParent+sizeof(pointer)*2;
  23. vmtMethodTable = vmtParent+sizeof(pointer)*3;
  24. vmtFieldTable = vmtParent+sizeof(pointer)*4;
  25. vmtTypeInfo = vmtParent+sizeof(pointer)*5;
  26. vmtInitTable = vmtParent+sizeof(pointer)*6;
  27. vmtAutoTable = vmtParent+sizeof(pointer)*7;
  28. vmtIntfTable = vmtParent+sizeof(pointer)*8;
  29. vmtMsgStrPtr = vmtParent+sizeof(pointer)*9;
  30. { methods }
  31. vmtMethodStart = vmtParent+sizeof(pointer)*10;
  32. vmtDestroy = vmtMethodStart;
  33. vmtNewInstance = vmtMethodStart+sizeof(pointer);
  34. vmtFreeInstance = vmtMethodStart+sizeof(pointer)*2;
  35. vmtSafeCallException = vmtMethodStart+sizeof(pointer)*3;
  36. vmtDefaultHandler = vmtMethodStart+sizeof(pointer)*4;
  37. vmtAfterConstruction = vmtMethodStart+sizeof(pointer)*5;
  38. vmtBeforeDestruction = vmtMethodStart+sizeof(pointer)*6;
  39. vmtDefaultHandlerStr = vmtMethodStart+sizeof(pointer)*7;
  40. { IInterface }
  41. S_OK = 0;
  42. S_FALSE = 1;
  43. E_NOINTERFACE = hresult($80004002);
  44. E_UNEXPECTED = hresult($8000FFFF);
  45. E_NOTIMPL = hresult($80004001);
  46. type
  47. TextFile = Text;
  48. { now the let's declare the base classes for the class object }
  49. { model }
  50. TObject = class;
  51. TClass = class of tobject;
  52. PClass = ^tclass;
  53. { to access the message table from outside }
  54. TMsgStrTable = record
  55. name : pshortstring;
  56. method : pointer;
  57. end;
  58. PMsgStrTable = ^TMsgStrTable;
  59. TStringMessageTable = record
  60. count : dword;
  61. msgstrtable : array[0..0] of tmsgstrtable;
  62. end;
  63. pstringmessagetable = ^tstringmessagetable;
  64. PGuid = ^TGuid;
  65. TGuid = packed record
  66. case integer of
  67. 1 : (
  68. Data1 : DWord;
  69. Data2 : word;
  70. Data3 : word;
  71. Data4 : array[0..7] of byte;
  72. );
  73. 2 : (
  74. D1 : DWord;
  75. D2 : word;
  76. D3 : word;
  77. D4 : array[0..7] of byte;
  78. );
  79. end;
  80. pinterfaceentry = ^tinterfaceentry;
  81. tinterfaceentry = packed record
  82. IID: pguid; { if assigned(IID) then Com else Corba}
  83. VTable: Pointer;
  84. IOffset: DWord;
  85. IIDStr: pshortstring; { never nil. Com: upper(GuidToString(IID^)) }
  86. end;
  87. pinterfacetable = ^tinterfacetable;
  88. tinterfacetable = packed record
  89. EntryCount: Word;
  90. Entries: array[0..0] of tinterfaceentry;
  91. end;
  92. TObject = class
  93. public
  94. { please don't change the order of virtual methods, because
  95. their vmt offsets are used by some assembler code which uses
  96. hard coded addresses (FK) }
  97. constructor Create;
  98. { the virtual procedures must be in THAT order }
  99. destructor Destroy;virtual;
  100. class function newinstance : tobject;virtual;
  101. procedure FreeInstance;virtual;
  102. function SafeCallException(exceptobject : tobject;
  103. exceptaddr : pointer) : longint;virtual;
  104. procedure DefaultHandler(var message);virtual;
  105. procedure Free;
  106. class function InitInstance(instance : pointer) : tobject;
  107. procedure CleanupInstance;
  108. class function ClassType : tclass;
  109. class function ClassInfo : pointer;
  110. class function ClassName : shortstring;
  111. class function ClassNameIs(const name : string) : boolean;
  112. class function ClassParent : tclass;
  113. class function InstanceSize : longint;
  114. class function InheritsFrom(aclass : tclass) : boolean;
  115. class function StringMessageTable : pstringmessagetable;
  116. { message handling routines }
  117. procedure Dispatch(var message);
  118. procedure DispatchStr(var message);
  119. class function MethodAddress(const name : shortstring) : pointer;
  120. class function MethodName(address : pointer) : shortstring;
  121. function FieldAddress(const name : shortstring) : pointer;
  122. { new since Delphi 4 }
  123. procedure AfterConstruction;virtual;
  124. procedure BeforeDestruction;virtual;
  125. { new for gtk, default handler for text based messages }
  126. procedure DefaultHandlerStr(var message);virtual;
  127. {$ifdef HASINTF}
  128. { interface functions }
  129. function GetInterface(const iid : tguid; out obj) : boolean;
  130. function GetInterfaceByStr(const iidstr : string; out obj) : boolean;
  131. class function GetInterfaceEntry(const iid : tguid) : pinterfaceentry;
  132. class function GetInterfaceEntryByStr(const iidstr : string) : pinterfaceentry;
  133. class function GetInterfaceTable : pinterfacetable;
  134. {$endif HASINTF}
  135. end;
  136. {$ifdef HASINTF}
  137. IUnknown = interface
  138. ['{00000000-0000-0000-C000-000000000046}']
  139. function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
  140. function _AddRef : longint;stdcall;
  141. function _Release : longint;stdcall;
  142. end;
  143. IInterface = IUnknown;
  144. {$M+}
  145. IInvokable = interface(IInterface)
  146. end;
  147. {$M-}
  148. { for native dispinterface support }
  149. IDispatch = interface(IUnknown)
  150. ['{00020400-0000-0000-C000-000000000046}']
  151. function GetTypeInfoCount(out count : longint) : longint;stdcall;
  152. function GetTypeInfo(Index,LocaleID : longint;
  153. out TypeInfo): LongInt;stdcall;
  154. function GetIDsOfNames(const iid: TGUID; names: Pointer;
  155. NameCount, LocaleID: LongInt; DispIDs: Pointer) : longint;stdcall;
  156. function Invoke(DispID: LongInt;const iid : TGUID;
  157. LocaleID : longint; Flags: Word;var params;
  158. VarResult,ExcepInfo,ArgErr : pointer) : longint;stdcall;
  159. end;
  160. TInterfacedObject = class(TObject,IUnknown)
  161. protected
  162. frefcount : longint;
  163. { implement methods of IUnknown }
  164. function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
  165. function _AddRef : longint;stdcall;
  166. function _Release : longint;stdcall;
  167. public
  168. procedure AfterConstruction;override;
  169. procedure BeforeDestruction;override;
  170. class function NewInstance : TObject;override;
  171. property RefCount : longint read frefcount;
  172. end;
  173. TInterfacedClass = class of TInterfacedObject;
  174. { some pointer definitions }
  175. PUnknown = ^IUnknown;
  176. PPUnknown = ^PUnknown;
  177. PDispatch = ^IDispatch;
  178. PPDispatch = ^PDispatch;
  179. {$endif HASINTF}
  180. TExceptProc = Procedure (Obj : TObject; Addr : Pointer; FrameCount:Longint; Frame: PPointer);
  181. { Exception object stack }
  182. PExceptObject = ^TExceptObject;
  183. TExceptObject = record
  184. FObject : TObject;
  185. Addr : pointer;
  186. Next : PExceptObject;
  187. refcount : Longint;
  188. Framecount : Longint;
  189. Frames : PPointer;
  190. end;
  191. Const
  192. ExceptProc : TExceptProc = Nil;
  193. RaiseProc : TExceptProc = Nil;
  194. RaiseMaxFrameCount : Longint = 16;
  195. Function RaiseList : PExceptObject;
  196. { @abstract(increase exception reference count)
  197. When leaving an except block, the exception object is normally
  198. freed automatically. To avoid this, call this function.
  199. If within the exception object you decide that you don't need
  200. the exception after all, call @link(ReleaseExceptionObject).
  201. Otherwise, if the reference count is > 0, the exception object
  202. goes into your "property" and you need to free it manually.
  203. The effect of this function is countered by re-raising an exception
  204. via "raise;", this zeroes the reference count again.
  205. Calling this method is only valid within an except block.
  206. @return(pointer to the exception object) }
  207. function AcquireExceptionObject: Pointer;
  208. { @abstract(decrease exception reference count)
  209. After calling @link(AcquireExceptionObject) you can call this method
  210. to decrease the exception reference count again.
  211. If the reference count is > 0, the exception object
  212. goes into your "property" and you need to free it manually.
  213. Calling this method is only valid within an except block. }
  214. procedure ReleaseExceptionObject;
  215. {*****************************************************************************
  216. Array of const support
  217. *****************************************************************************}
  218. const
  219. vtInteger = 0;
  220. vtBoolean = 1;
  221. vtChar = 2;
  222. vtExtended = 3;
  223. vtString = 4;
  224. vtPointer = 5;
  225. vtPChar = 6;
  226. vtObject = 7;
  227. vtClass = 8;
  228. vtWideChar = 9;
  229. vtPWideChar = 10;
  230. vtAnsiString = 11;
  231. vtCurrency = 12;
  232. vtVariant = 13;
  233. vtInterface = 14;
  234. vtWideString = 15;
  235. vtInt64 = 16;
  236. vtQWord = 17;
  237. type
  238. PVarRec = ^TVarRec;
  239. TVarRec = record
  240. case VType : Ptrint of
  241. vtInteger : (VInteger: Longint);
  242. {$ifdef ENDIAN_BIG}
  243. vtBoolean : (booldummy1,booldummy2,booldummy3: byte; VBoolean: Boolean);
  244. vtChar : (chardummy1,chardummy2,chardummy3: byte; VChar: Char);
  245. vtWideChar : (wchardummy1,VWideChar: WideChar);
  246. {$else ENDIAN_BIG}
  247. vtBoolean : (VBoolean: Boolean);
  248. vtChar : (VChar: Char);
  249. vtWideChar : (VWideChar: WideChar);
  250. {$endif ENDIAN_BIG}
  251. vtExtended : (VExtended: PExtended);
  252. vtString : (VString: PShortString);
  253. vtPointer : (VPointer: Pointer);
  254. vtPChar : (VPChar: PChar);
  255. vtObject : (VObject: TObject);
  256. vtClass : (VClass: TClass);
  257. vtPWideChar : (VPWideChar: PWideChar);
  258. vtAnsiString : (VAnsiString: Pointer);
  259. {$ifdef HASCURRENCY}
  260. vtCurrency : (VCurrency: PCurrency);
  261. {$endif HASCURRENCY}
  262. {$ifdef HASVARIANT}
  263. vtVariant : (VVariant: PVariant);
  264. {$endif HASVARIANT}
  265. vtInterface : (VInterface: Pointer);
  266. vtWideString : (VWideString: Pointer);
  267. vtInt64 : (VInt64: PInt64);
  268. vtQWord : (VQWord: PQWord);
  269. end;
  270. {
  271. $Log$
  272. Revision 1.26 2005-01-31 19:41:39 peter
  273. * interface additions
  274. Revision 1.25 2005/01/26 17:07:10 peter
  275. * retrieve backtrace when exception is raised
  276. * RaiseMaxFrameCount added to limit the number of backtraces, setting
  277. it to 0 disables backtraces. Default is 16
  278. Revision 1.24 2004/04/28 19:52:41 peter
  279. * vtype changed to ptrint
  280. Revision 1.23 2004/04/26 21:06:00 peter
  281. * class size changed to aint
  282. Revision 1.22 2004/04/25 16:32:31 florian
  283. * fixed vmt issues on 64 bit systems
  284. Revision 1.21 2003/12/06 00:02:34 florian
  285. * widechars in tvarrec fixed for big endian machines as well
  286. Revision 1.20 2003/12/05 23:54:04 jonas
  287. * changed tvarrec so chars and booleans work on big endian machines
  288. Revision 1.19 2003/11/30 19:48:20 florian
  289. * fixed some arm stuff
  290. Revision 1.18 2003/11/03 09:42:28 marco
  291. * Peter's Cardinal<->Longint fixes patch
  292. Revision 1.17 2003/10/06 15:59:20 florian
  293. + applied patch for ref. counted exceptions by Johannes Berg
  294. Revision 1.16 2003/03/17 20:55:58 peter
  295. * ClassType changed to class method
  296. Revision 1.15 2002/09/26 14:43:24 florian
  297. + tvarrec field vcurrency for compilers with hascurrency released
  298. Revision 1.14 2002/09/07 15:07:46 peter
  299. * old logs removed and tabs fixed
  300. }