objpash.inc 12 KB

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