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: LongInt;
  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. 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. end;
  183. Const
  184. ExceptProc : TExceptProc = Nil;
  185. RaiseProc : TExceptProc = Nil;
  186. Function RaiseList : PExceptObject;
  187. {*****************************************************************************
  188. Array of const support
  189. *****************************************************************************}
  190. const
  191. vtInteger = 0;
  192. vtBoolean = 1;
  193. vtChar = 2;
  194. vtExtended = 3;
  195. vtString = 4;
  196. vtPointer = 5;
  197. vtPChar = 6;
  198. vtObject = 7;
  199. vtClass = 8;
  200. vtWideChar = 9;
  201. vtPWideChar = 10;
  202. vtAnsiString = 11;
  203. vtCurrency = 12;
  204. vtVariant = 13;
  205. vtInterface = 14;
  206. vtWideString = 15;
  207. vtInt64 = 16;
  208. vtQWord = 17;
  209. type
  210. PVarRec = ^TVarRec;
  211. TVarRec = record
  212. case VType : Longint of
  213. vtInteger : (VInteger: Longint);
  214. vtBoolean : (VBoolean: Boolean);
  215. vtChar : (VChar: Char);
  216. vtExtended : (VExtended: PExtended);
  217. vtString : (VString: PShortString);
  218. vtPointer : (VPointer: Pointer);
  219. vtPChar : (VPChar: PChar);
  220. vtObject : (VObject: TObject);
  221. vtClass : (VClass: TClass);
  222. vtWideChar : (VWideChar: WideChar);
  223. vtPWideChar : (VPWideChar: PWideChar);
  224. vtAnsiString : (VAnsiString: Pointer);
  225. // vtCurrency : (VCurrency: PCurrency);
  226. {$ifdef HASVARIANT}
  227. vtVariant : (VVariant: PVariant);
  228. {$endif HASVARIANT}
  229. vtInterface : (VInterface: Pointer);
  230. vtWideString : (VWideString: Pointer);
  231. vtInt64 : (VInt64: PInt64);
  232. vtQWord : (VQWord: PQWord);
  233. end;
  234. {
  235. $Log$
  236. Revision 1.13 2001-08-19 21:02:01 florian
  237. * fixed and added a lot of stuff to get the Jedi DX( headers
  238. compiled
  239. Revision 1.12 2001/08/12 22:11:48 peter
  240. * freeandnil added
  241. Revision 1.11 2001/04/13 23:49:48 peter
  242. * fixes for the stricter compiler
  243. Revision 1.10 2001/04/04 17:56:45 florian
  244. * TGUID definition from win32/wininc/struct.inc copied
  245. Revision 1.9 2001/03/22 23:26:37 florian
  246. * some types moved to systemh
  247. + some types like PDispatch added
  248. Revision 1.8 2000/11/07 23:42:21 florian
  249. + AfterConstruction and BeforeDestruction implemented
  250. + TInterfacedObject implemented
  251. Revision 1.7 2000/11/06 20:34:24 peter
  252. * changed ver1_0 defines to temporary defs
  253. Revision 1.6 2000/11/04 17:31:50 florian
  254. * fixed some out declarations
  255. Revision 1.5 2000/11/04 16:28:55 florian
  256. + interfaces support
  257. Revision 1.4 2000/09/30 07:38:07 sg
  258. * Added 'RaiseProc': A user-definable callback procedure which gets
  259. called whenever an exception is being raised
  260. Revision 1.3 2000/07/14 10:33:10 michael
  261. + Conditionals fixed
  262. Revision 1.2 2000/07/13 11:33:45 michael
  263. + removed logs
  264. }