objpash.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. { some pointer definitions }
  42. pshortstring = ^shortstring;
  43. plongstring = ^longstring;
  44. pansistring = ^ansistring;
  45. pwidestring = ^widestring;
  46. // pstring = pansistring;
  47. pextended = ^extended;
  48. ppointer = ^pointer;
  49. { now the let's declare the base classes for the class object }
  50. { model }
  51. tobject = class;
  52. tclass = class of tobject;
  53. pclass = ^tclass;
  54. { to access the message table from outside }
  55. tmsgstrtable = record
  56. name : pshortstring;
  57. method : pointer;
  58. end;
  59. pmsgstrtable = ^tmsgstrtable;
  60. tstringmessagetable = record
  61. count : dword;
  62. msgstrtable : array[0..0] of tmsgstrtable;
  63. end;
  64. pstringmessagetable = ^tstringmessagetable;
  65. pguid = ^tguid;
  66. tguid = packed record
  67. D1: LongWord;
  68. D2: Word;
  69. D3: Word;
  70. D4: array[0..7] of Byte;
  71. end;
  72. pinterfaceentry = ^tinterfaceentry;
  73. tinterfaceentry = packed record
  74. IID: pguid; { if assigned(IID) then Com else Corba}
  75. VTable: Pointer;
  76. IOffset: LongInt;
  77. IIDStr: pshortstring; { never nil. Com: upper(GuidToString(IID^)) }
  78. end;
  79. pinterfacetable = ^tinterfacetable;
  80. tinterfacetable = packed record
  81. EntryCount: Word;
  82. Entries: array[0..0] of tinterfaceentry;
  83. end;
  84. tobject = class
  85. public
  86. { please don't change the order of virtual methods, because }
  87. { their vmt offsets are used by some assembler code which uses }
  88. { hard coded addresses (FK) }
  89. constructor create;
  90. { the virtual procedures must be in THAT order }
  91. destructor destroy;virtual;
  92. class function newinstance : tobject;virtual;
  93. procedure freeinstance;virtual;
  94. function safecallexception(exceptobject : tobject;
  95. exceptaddr : pointer) : longint;virtual;
  96. procedure defaulthandler(var message);virtual;
  97. procedure free;
  98. class function initinstance(instance : pointer) : tobject;
  99. procedure cleanupinstance;
  100. function classtype : tclass;
  101. class function classinfo : pointer;
  102. class function classname : shortstring;
  103. class function classnameis(const name : string) : boolean;
  104. class function classparent : tclass;
  105. class function instancesize : longint;
  106. class function inheritsfrom(aclass : tclass) : boolean;
  107. class function stringmessagetable : pstringmessagetable;
  108. { message handling routines }
  109. procedure dispatch(var message);
  110. procedure dispatchstr(var message);
  111. class function methodaddress(const name : shortstring) : pointer;
  112. class function methodname(address : pointer) : shortstring;
  113. function fieldaddress(const name : shortstring) : pointer;
  114. { new since Delphi 4 }
  115. procedure AfterConstruction;virtual;
  116. procedure BeforeDestruction;virtual;
  117. { new for gtk, default handler for text based messages }
  118. procedure DefaultHandlerStr(var message);virtual;
  119. {$ifdef HASINTF}
  120. { interface functions }
  121. function getinterface(const iid : tguid; out obj) : boolean;
  122. function getinterfacebystr(const iidstr : string; out obj) : boolean;
  123. class function getinterfaceentry(const iid : tguid) : pinterfaceentry;
  124. class function getinterfaceentrybystr(const iidstr : string) : pinterfaceentry;
  125. class function getinterfacetable : pinterfacetable;
  126. {$endif HASINTF}
  127. end;
  128. {$ifdef HASINTF}
  129. IUnknown = interface
  130. ['{00000000-0000-0000-C000-000000000046}']
  131. function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
  132. function _AddRef : longint;stdcall;
  133. function _Release : longint;stdcall;
  134. end;
  135. { for native dispinterface support }
  136. IDispatch = interface(IUnknown)
  137. ['{00020400-0000-0000-C000-000000000046}']
  138. function GetTypeInfoCount(out count : longint) : longint;stdcall;
  139. function GetTypeInfo(Index,LocaleID : longint;
  140. out TypeInfo): LongInt;stdcall;
  141. function GetIDsOfNames(const iid: TGUID; names: Pointer;
  142. NameCount, LocaleID: LongInt; DispIDs: Pointer) : longint;stdcall;
  143. function Invoke(DispID: LongInt;const iid : TGUID;
  144. LocaleID : longint; Flags: Word;var params;
  145. VarResult,ExcepInfo,ArgErr : pointer) : longint;stdcall;
  146. end;
  147. TInterfacedObject = class(TObject,IUnknown)
  148. protected
  149. frefcount : longint;
  150. { implement methods of IUnknown }
  151. function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
  152. function _AddRef : longint;stdcall;
  153. function _Release : longint;stdcall;
  154. public
  155. procedure AfterConstruction;override;
  156. procedure BeforeDestruction;override;
  157. class function NewInstance : TObject;override;
  158. property RefCount : longint read frefcount;
  159. end;
  160. {$endif HASINTF}
  161. TExceptProc = Procedure (Obj : TObject; Addr,Frame: Pointer);
  162. { Exception object stack }
  163. PExceptObject = ^TExceptObject;
  164. TExceptObject = record
  165. FObject : TObject;
  166. Addr,
  167. Frame : pointer;
  168. Next : PExceptObject;
  169. end;
  170. Const
  171. ExceptProc : TExceptProc = Nil;
  172. RaiseProc : TExceptProc = Nil;
  173. Function RaiseList : PExceptObject;
  174. {*****************************************************************************
  175. Variant Type
  176. *****************************************************************************}
  177. Const
  178. varEmpty = $0000;
  179. varNull = $0001;
  180. varSmallint = $0002;
  181. varInteger = $0003;
  182. varSingle = $0004;
  183. varDouble = $0005;
  184. varCurrency = $0006;
  185. varDate = $0007;
  186. varOleStr = $0008;
  187. varDispatch = $0009;
  188. varError = $000A;
  189. varBoolean = $000B;
  190. varVariant = $000C;
  191. varUnknown = $000D;
  192. varByte = $0011;
  193. varString = $0100;
  194. varAny = $0101;
  195. varTypeMask = $0FFF;
  196. varArray = $2000;
  197. varByRef = $4000;
  198. vtInteger = 0;
  199. vtBoolean = 1;
  200. vtChar = 2;
  201. vtExtended = 3;
  202. vtString = 4;
  203. vtPointer = 5;
  204. vtPChar = 6;
  205. vtObject = 7;
  206. vtClass = 8;
  207. vtWideChar = 9;
  208. vtPWideChar = 10;
  209. vtAnsiString = 11;
  210. vtCurrency = 12;
  211. vtVariant = 13;
  212. vtInterface = 14;
  213. vtWideString = 15;
  214. vtInt64 = 16;
  215. vtQWord = 17;
  216. Type
  217. PVarRec = ^TVarRec;
  218. TVarRec = record
  219. case VType : Longint of
  220. vtInteger : (VInteger: Longint);
  221. vtBoolean : (VBoolean: Boolean);
  222. vtChar : (VChar: Char);
  223. vtExtended : (VExtended: PExtended);
  224. vtString : (VString: PShortString);
  225. vtPointer : (VPointer: Pointer);
  226. vtPChar : (VPChar: PChar);
  227. vtObject : (VObject: TObject);
  228. vtClass : (VClass: TClass);
  229. // vtWideChar : (VWideChar: WideChar);
  230. // vtPWideChar : (VPWideChar: PWideChar);
  231. vtAnsiString : (VAnsiString: Pointer);
  232. // vtCurrency : (VCurrency: PCurrency);
  233. // vtVariant : (VVariant: PVariant);
  234. vtInterface : (VInterface: Pointer);
  235. vtWideString : (VWideString: Pointer);
  236. vtInt64 : (VInt64: PInt64);
  237. vtQWord : (VQWord: PQWord);
  238. end;
  239. {
  240. $Log$
  241. Revision 1.8 2000-11-07 23:42:21 florian
  242. + AfterConstruction and BeforeDestruction implemented
  243. + TInterfacedObject implemented
  244. Revision 1.7 2000/11/06 20:34:24 peter
  245. * changed ver1_0 defines to temporary defs
  246. Revision 1.6 2000/11/04 17:31:50 florian
  247. * fixed some out declarations
  248. Revision 1.5 2000/11/04 16:28:55 florian
  249. + interfaces support
  250. Revision 1.4 2000/09/30 07:38:07 sg
  251. * Added 'RaiseProc': A user-definable callback procedure which gets
  252. called whenever an exception is being raised
  253. Revision 1.3 2000/07/14 10:33:10 michael
  254. + Conditionals fixed
  255. Revision 1.2 2000/07/13 11:33:45 michael
  256. + removed logs
  257. }