objpash.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. IInterface = IUnknown;
  137. { for native dispinterface support }
  138. IDispatch = interface(IUnknown)
  139. ['{00020400-0000-0000-C000-000000000046}']
  140. function GetTypeInfoCount(out count : longint) : longint;stdcall;
  141. function GetTypeInfo(Index,LocaleID : longint;
  142. out TypeInfo): LongInt;stdcall;
  143. function GetIDsOfNames(const iid: TGUID; names: Pointer;
  144. NameCount, LocaleID: LongInt; DispIDs: Pointer) : longint;stdcall;
  145. function Invoke(DispID: LongInt;const iid : TGUID;
  146. LocaleID : longint; Flags: Word;var params;
  147. VarResult,ExcepInfo,ArgErr : pointer) : longint;stdcall;
  148. end;
  149. TInterfacedObject = class(TObject,IUnknown)
  150. protected
  151. frefcount : longint;
  152. { implement methods of IUnknown }
  153. function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
  154. function _AddRef : longint;stdcall;
  155. function _Release : longint;stdcall;
  156. public
  157. procedure AfterConstruction;override;
  158. procedure BeforeDestruction;override;
  159. class function NewInstance : TObject;override;
  160. property RefCount : longint read frefcount;
  161. end;
  162. { some pointer definitions }
  163. PUnknown = ^IUnknown;
  164. PPUnknown = ^PUnknown;
  165. PDispatch = ^IDispatch;
  166. PPDispatch = ^PDispatch;
  167. {$endif HASINTF}
  168. TExceptProc = Procedure (Obj : TObject; Addr,Frame: Pointer);
  169. { Exception object stack }
  170. PExceptObject = ^TExceptObject;
  171. TExceptObject = record
  172. FObject : TObject;
  173. Addr,
  174. Frame : pointer;
  175. Next : PExceptObject;
  176. end;
  177. Const
  178. ExceptProc : TExceptProc = Nil;
  179. RaiseProc : TExceptProc = Nil;
  180. Function RaiseList : PExceptObject;
  181. {*****************************************************************************
  182. Variant Type
  183. *****************************************************************************}
  184. Const
  185. varEmpty = $0000;
  186. varNull = $0001;
  187. varSmallint = $0002;
  188. varInteger = $0003;
  189. varSingle = $0004;
  190. varDouble = $0005;
  191. varCurrency = $0006;
  192. varDate = $0007;
  193. varOleStr = $0008;
  194. varDispatch = $0009;
  195. varError = $000A;
  196. varBoolean = $000B;
  197. varVariant = $000C;
  198. varUnknown = $000D;
  199. varByte = $0011;
  200. varString = $0100;
  201. varAny = $0101;
  202. varTypeMask = $0FFF;
  203. varArray = $2000;
  204. varByRef = $4000;
  205. vtInteger = 0;
  206. vtBoolean = 1;
  207. vtChar = 2;
  208. vtExtended = 3;
  209. vtString = 4;
  210. vtPointer = 5;
  211. vtPChar = 6;
  212. vtObject = 7;
  213. vtClass = 8;
  214. vtWideChar = 9;
  215. vtPWideChar = 10;
  216. vtAnsiString = 11;
  217. vtCurrency = 12;
  218. vtVariant = 13;
  219. vtInterface = 14;
  220. vtWideString = 15;
  221. vtInt64 = 16;
  222. vtQWord = 17;
  223. Type
  224. PVarRec = ^TVarRec;
  225. TVarRec = record
  226. case VType : Longint of
  227. vtInteger : (VInteger: Longint);
  228. vtBoolean : (VBoolean: Boolean);
  229. vtChar : (VChar: Char);
  230. vtExtended : (VExtended: PExtended);
  231. vtString : (VString: PShortString);
  232. vtPointer : (VPointer: Pointer);
  233. vtPChar : (VPChar: PChar);
  234. vtObject : (VObject: TObject);
  235. vtClass : (VClass: TClass);
  236. // vtWideChar : (VWideChar: WideChar);
  237. // vtPWideChar : (VPWideChar: PWideChar);
  238. vtAnsiString : (VAnsiString: Pointer);
  239. // vtCurrency : (VCurrency: PCurrency);
  240. // vtVariant : (VVariant: PVariant);
  241. vtInterface : (VInterface: Pointer);
  242. vtWideString : (VWideString: Pointer);
  243. vtInt64 : (VInt64: PInt64);
  244. vtQWord : (VQWord: PQWord);
  245. end;
  246. {
  247. $Log$
  248. Revision 1.12 2001-08-12 22:11:48 peter
  249. * freeandnil added
  250. Revision 1.11 2001/04/13 23:49:48 peter
  251. * fixes for the stricter compiler
  252. Revision 1.10 2001/04/04 17:56:45 florian
  253. * TGUID definition from win32/wininc/struct.inc copied
  254. Revision 1.9 2001/03/22 23:26:37 florian
  255. * some types moved to systemh
  256. + some types like PDispatch added
  257. Revision 1.8 2000/11/07 23:42:21 florian
  258. + AfterConstruction and BeforeDestruction implemented
  259. + TInterfacedObject implemented
  260. Revision 1.7 2000/11/06 20:34:24 peter
  261. * changed ver1_0 defines to temporary defs
  262. Revision 1.6 2000/11/04 17:31:50 florian
  263. * fixed some out declarations
  264. Revision 1.5 2000/11/04 16:28:55 florian
  265. + interfaces support
  266. Revision 1.4 2000/09/30 07:38:07 sg
  267. * Added 'RaiseProc': A user-definable callback procedure which gets
  268. called whenever an exception is being raised
  269. Revision 1.3 2000/07/14 10:33:10 michael
  270. + Conditionals fixed
  271. Revision 1.2 2000/07/13 11:33:45 michael
  272. + removed logs
  273. }