objpash.inc 11 KB

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