objpash.inc 11 KB

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