typinfo.pp 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. member of the Free Pascal development team
  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. { This unit provides the same Functionality as the TypInfo Unit }
  12. { of Delphi }
  13. unit typinfo;
  14. interface
  15. {$MODE objfpc}
  16. {$MODESWITCH AdvancedRecords}
  17. {$inline on}
  18. {$macro on}
  19. {$h+}
  20. uses SysUtils;
  21. // temporary types:
  22. type
  23. {$MINENUMSIZE 1 this saves a lot of memory }
  24. {$ifdef FPC_RTTI_PACKSET1}
  25. { for Delphi compatibility }
  26. {$packset 1}
  27. {$endif}
  28. // if you change one of the following enumeration types
  29. // you have also to change the compiler in an appropriate way !
  30. TTypeKind = (tkUnknown,tkInteger,tkChar,tkEnumeration,tkFloat,
  31. tkSet,tkMethod,tkSString,tkLString,tkAString,
  32. tkWString,tkVariant,tkArray,tkRecord,tkInterface,
  33. tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord,
  34. tkDynArray,tkInterfaceRaw,tkProcVar,tkUString,tkUChar,
  35. tkHelper,tkFile,tkClassRef,tkPointer);
  36. TOrdType = (otSByte,otUByte,otSWord,otUWord,otSLong,otULong);
  37. {$ifndef FPUNONE}
  38. TFloatType = (ftSingle,ftDouble,ftExtended,ftComp,ftCurr);
  39. {$endif}
  40. TMethodKind = (mkProcedure,mkFunction,mkConstructor,mkDestructor,
  41. mkClassProcedure,mkClassFunction,mkClassConstructor,
  42. mkClassDestructor,mkOperatorOverload);
  43. TParamFlag = (pfVar,pfConst,pfArray,pfAddress,pfReference,pfOut);
  44. TParamFlags = set of TParamFlag;
  45. TIntfFlag = (ifHasGuid,ifDispInterface,ifDispatch,ifHasStrGUID);
  46. TIntfFlags = set of TIntfFlag;
  47. TIntfFlagsBase = set of TIntfFlag;
  48. // don't rely on integer values of TCallConv since it includes all conventions
  49. // which both delphi and fpc support. In the future delphi can support more and
  50. // fpc own conventions will be shifted/reordered accordinly
  51. TCallConv = (ccReg, ccCdecl, ccPascal, ccStdCall, ccSafeCall,
  52. ccCppdecl, ccFar16, ccOldFPCCall, ccInternProc,
  53. ccSysCall, ccSoftFloat, ccMWPascal);
  54. {$MINENUMSIZE DEFAULT}
  55. const
  56. ptField = 0;
  57. ptStatic = 1;
  58. ptVirtual = 2;
  59. ptConst = 3;
  60. type
  61. TTypeKinds = set of TTypeKind;
  62. ShortStringBase = string[255];
  63. PVmtFieldEntry = ^TVmtFieldEntry;
  64. TVmtFieldEntry =
  65. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  66. packed
  67. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  68. record
  69. FieldOffset: PtrUInt;
  70. TypeIndex: Word;
  71. Name: ShortString;
  72. end;
  73. PVmtFieldTable = ^TVmtFieldTable;
  74. TVmtFieldTable =
  75. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  76. packed
  77. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  78. record
  79. Count: Word;
  80. ClassTab: Pointer;
  81. { should be array[Word] of TFieldInfo; but
  82. Elements have variant size! force at least proper alignment }
  83. Fields: array[0..0] of TVmtFieldEntry
  84. end;
  85. {$PACKRECORDS 1}
  86. TTypeInfo = record
  87. Kind : TTypeKind;
  88. Name : ShortString;
  89. // here the type data follows as TTypeData record
  90. end;
  91. PTypeInfo = ^TTypeInfo;
  92. PPTypeInfo = ^PTypeInfo;
  93. { Note: these are only for backwards compatibility. New type references should
  94. only use PPTypeInfo directly! }
  95. {$ifdef ver3_0}
  96. {$define TypeInfoPtr := PTypeInfo}
  97. {$else}
  98. {$define TypeInfoPtr := PPTypeInfo}
  99. {$endif}
  100. {$PACKRECORDS C}
  101. // members of TTypeData
  102. TArrayTypeData =
  103. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  104. packed
  105. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  106. record
  107. private
  108. function GetElType: PTypeInfo; inline;
  109. function GetDims(aIndex: Byte): PTypeInfo; inline;
  110. public
  111. property ElType: PTypeInfo read GetElType;
  112. property Dims[Index: Byte]: PTypeInfo read GetDims;
  113. public
  114. Size: SizeInt;
  115. ElCount: SizeInt;
  116. ElTypeRef: TypeInfoPtr;
  117. DimCount: Byte;
  118. DimsRef: array[0..255] of TypeInfoPtr;
  119. end;
  120. PManagedField = ^TManagedField;
  121. TManagedField =
  122. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  123. packed
  124. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  125. record
  126. private
  127. function GetTypeRef: PTypeInfo; inline;
  128. public
  129. property TypeRef: PTypeInfo read GetTypeRef;
  130. public
  131. TypeRefRef: TypeInfoPtr;
  132. FldOffset: SizeInt;
  133. end;
  134. PProcedureParam = ^TProcedureParam;
  135. TProcedureParam =
  136. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  137. packed
  138. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  139. record
  140. private
  141. function GetParamType: PTypeInfo; inline;
  142. public
  143. property ParamType: PTypeInfo read GetParamType;
  144. public
  145. Flags: Byte;
  146. ParamTypeRef: TypeInfoPtr;
  147. Name: ShortString;
  148. end;
  149. TProcedureSignature =
  150. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  151. packed
  152. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  153. record
  154. private
  155. function GetResultType: PTypeInfo; inline;
  156. public
  157. property ResultType: PTypeInfo read GetResultType;
  158. public
  159. Flags: Byte;
  160. CC: TCallConv;
  161. ResultTypeRef: TypeInfoPtr;
  162. ParamCount: Byte;
  163. {Params: array[0..ParamCount - 1] of TProcedureParam;}
  164. function GetParam(ParamIndex: Integer): PProcedureParam;
  165. end;
  166. PTypeData = ^TTypeData;
  167. TTypeData =
  168. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  169. packed
  170. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  171. record
  172. private
  173. function GetBaseType: PTypeInfo; inline;
  174. function GetCompType: PTypeInfo; inline;
  175. function GetParentInfo: PTypeInfo; inline;
  176. function GetHelperParent: PTypeInfo; inline;
  177. function GetExtendedInfo: PTypeInfo; inline;
  178. function GetIntfParent: PTypeInfo; inline;
  179. function GetRawIntfParent: PTypeInfo; inline;
  180. function GetElType: PTypeInfo; inline;
  181. function GetElType2: PTypeInfo; inline;
  182. function GetInstanceType: PTypeInfo; inline;
  183. function GetRefType: PTypeInfo; inline;
  184. public
  185. { tkEnumeration }
  186. property BaseType: PTypeInfo read GetBaseType;
  187. { tkSet }
  188. property CompType: PTypeInfo read GetCompType;
  189. { tkClass }
  190. property ParentInfo: PTypeInfo read GetParentInfo;
  191. { tkHelper }
  192. property HelperParent: PTypeInfo read GetHelperParent;
  193. property ExtendedInfo: PTypeInfo read GetExtendedInfo;
  194. { tkInterface }
  195. property IntfParent: PTypeInfo read GetIntfParent;
  196. { tkInterfaceRaw }
  197. property RawIntfParent: PTypeInfo read GetRawIntfParent;
  198. { tkDynArray }
  199. property ElType2: PTypeInfo read GetElType2;
  200. property ElType: PTypeInfo read GetElType;
  201. { tkClassRef }
  202. property InstanceType: PTypeInfo read GetInstanceType;
  203. { tkPointer }
  204. property RefType: PTypeInfo read GetRefType;
  205. public
  206. case TTypeKind of
  207. tkUnKnown,tkLString,tkWString,tkVariant,tkUString:
  208. ();
  209. tkAString:
  210. (CodePage: Word);
  211. tkInteger,tkChar,tkEnumeration,tkBool,tkWChar,tkSet:
  212. (OrdType : TOrdType;
  213. case TTypeKind of
  214. tkInteger,tkChar,tkEnumeration,tkBool,tkWChar : (
  215. MinValue,MaxValue : Longint;
  216. case TTypeKind of
  217. tkEnumeration:
  218. (
  219. BaseTypeRef : TypeInfoPtr;
  220. NameList : ShortString;
  221. {EnumUnitName: ShortString;})
  222. );
  223. tkSet:
  224. (CompTypeRef : TypeInfoPtr)
  225. );
  226. {$ifndef FPUNONE}
  227. tkFloat:
  228. (FloatType : TFloatType);
  229. {$endif}
  230. tkSString:
  231. (MaxLength : Byte);
  232. tkClass:
  233. (ClassType : TClass;
  234. ParentInfoRef : TypeInfoPtr;
  235. PropCount : SmallInt;
  236. UnitName : ShortString
  237. // here the properties follow as array of TPropInfo
  238. );
  239. tkRecord:
  240. (
  241. RecSize: Integer;
  242. ManagedFldCount: Integer;
  243. {ManagedFields: array[1..ManagedFldCount] of TManagedField}
  244. );
  245. tkHelper:
  246. (HelperParentRef : TypeInfoPtr;
  247. ExtendedInfoRef : TypeInfoPtr;
  248. HelperProps : SmallInt;
  249. HelperUnit : ShortString
  250. // here the properties follow as array of TPropInfo
  251. );
  252. tkMethod:
  253. (MethodKind : TMethodKind;
  254. ParamCount : Byte;
  255. ParamList : array[0..1023] of Char
  256. {in reality ParamList is a array[1..ParamCount] of:
  257. record
  258. Flags : TParamFlags;
  259. ParamName : ShortString;
  260. TypeName : ShortString;
  261. end;
  262. followed by
  263. ResultType : ShortString // for mkFunction, mkClassFunction only
  264. ResultTypeRef : PPTypeInfo; // for mkFunction, mkClassFunction only
  265. CC : TCallConv;
  266. ParamTypeRefs : array[1..ParamCount] of PPTypeInfo;}
  267. );
  268. tkProcVar:
  269. (ProcSig: TProcedureSignature);
  270. tkInt64:
  271. (MinInt64Value, MaxInt64Value: Int64);
  272. tkQWord:
  273. (MinQWordValue, MaxQWordValue: QWord);
  274. tkInterface:
  275. (
  276. IntfParentRef: TypeInfoPtr;
  277. IntfFlags : TIntfFlagsBase;
  278. GUID: TGUID;
  279. IntfUnit: ShortString;
  280. { here the properties follow as Word Count & array of TPropInfo }
  281. );
  282. tkInterfaceRaw:
  283. (
  284. RawIntfParentRef: TypeInfoPtr;
  285. RawIntfFlags : TIntfFlagsBase;
  286. IID: TGUID;
  287. RawIntfUnit: ShortString;
  288. IIDStr: ShortString;
  289. { here the properties follow as Word Count & array of TPropInfo }
  290. );
  291. tkArray:
  292. (ArrayData: TArrayTypeData);
  293. tkDynArray:
  294. (
  295. elSize : PtrUInt;
  296. elType2Ref : TypeInfoPtr;
  297. varType : Longint;
  298. elTypeRef : TypeInfoPtr;
  299. DynUnitName: ShortStringBase
  300. );
  301. tkClassRef:
  302. (InstanceTypeRef: TypeInfoPtr);
  303. tkPointer:
  304. (RefTypeRef: TypeInfoPtr);
  305. end;
  306. TPropData =
  307. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  308. packed
  309. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  310. record
  311. PropCount : Word;
  312. PropList : record _alignmentdummy : ptrint; end;
  313. end;
  314. {$PACKRECORDS 1}
  315. PPropInfo = ^TPropInfo;
  316. TPropInfo = packed record
  317. private
  318. function GetPropType: PTypeInfo; inline;
  319. public
  320. PropTypeRef : TypeInfoPtr;
  321. GetProc : CodePointer;
  322. SetProc : CodePointer;
  323. StoredProc : CodePointer;
  324. Index : Integer;
  325. Default : Longint;
  326. NameIndex : SmallInt;
  327. // contains the type of the Get/Set/Storedproc, see also ptxxx
  328. // bit 0..1 GetProc
  329. // 2..3 SetProc
  330. // 4..5 StoredProc
  331. // 6 : true, constant index property
  332. PropProcs : Byte;
  333. Name : ShortString;
  334. property PropType: PTypeInfo read GetPropType;
  335. end;
  336. TProcInfoProc = Procedure(PropInfo : PPropInfo) of object;
  337. PPropList = ^TPropList;
  338. TPropList = array[0..{$ifdef cpu16}(32768 div sizeof(PPropInfo))-2{$else}65535{$endif}] of PPropInfo;
  339. const
  340. tkString = tkSString;
  341. tkProcedure = tkProcVar; // for compatibility with Delphi
  342. tkAny = [Low(TTypeKind)..High(TTypeKind)];
  343. tkMethods = [tkMethod];
  344. tkProperties = tkAny-tkMethods-[tkUnknown];
  345. // general property handling
  346. Function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
  347. Function GetPropInfo(TypeInfo: PTypeInfo;const PropName: string): PPropInfo;
  348. Function GetPropInfo(TypeInfo: PTypeInfo;const PropName: string; AKinds: TTypeKinds): PPropInfo;
  349. Function GetPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  350. Function GetPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds): PPropInfo;
  351. Function GetPropInfo(AClass: TClass; const PropName: string): PPropInfo;
  352. Function GetPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds): PPropInfo;
  353. Function FindPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  354. Function FindPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds): PPropInfo;
  355. Function FindPropInfo(AClass: TClass; const PropName: string): PPropInfo;
  356. Function FindPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds): PPropInfo;
  357. Procedure GetPropInfos(TypeInfo: PTypeInfo; PropList: PPropList);
  358. Function GetPropList(TypeInfo: PTypeInfo; TypeKinds: TTypeKinds; PropList: PPropList; Sorted: boolean = true): longint;
  359. Function GetPropList(TypeInfo: PTypeInfo; out PropList: PPropList): SizeInt;
  360. function GetPropList(AClass: TClass; out PropList: PPropList): Integer;
  361. function GetPropList(Instance: TObject; out PropList: PPropList): Integer;
  362. // Property information routines.
  363. Function IsStoredProp(Instance: TObject;PropInfo : PPropInfo) : Boolean;
  364. Function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
  365. Function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
  366. Function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;
  367. Function PropType(Instance: TObject; const PropName: string): TTypeKind;
  368. Function PropType(AClass: TClass; const PropName: string): TTypeKind;
  369. Function PropIsType(Instance: TObject; const PropName: string; TypeKind: TTypeKind): Boolean;
  370. Function PropIsType(AClass: TClass; const PropName: string; TypeKind: TTypeKind): Boolean;
  371. // subroutines to read/write properties
  372. Function GetOrdProp(Instance: TObject; PropInfo : PPropInfo) : Int64;
  373. Function GetOrdProp(Instance: TObject; const PropName: string): Int64;
  374. Procedure SetOrdProp(Instance: TObject; PropInfo : PPropInfo; Value : Int64);
  375. Procedure SetOrdProp(Instance: TObject; const PropName: string; Value: Int64);
  376. Function GetEnumProp(Instance: TObject; const PropName: string): string;
  377. Function GetEnumProp(Instance: TObject; const PropInfo: PPropInfo): string;
  378. Procedure SetEnumProp(Instance: TObject; const PropName: string;const Value: string);
  379. Procedure SetEnumProp(Instance: TObject; const PropInfo: PPropInfo;const Value: string);
  380. Function GetSetProp(Instance: TObject; const PropName: string): string;
  381. Function GetSetProp(Instance: TObject; const PropName: string; Brackets: Boolean): string;
  382. Function GetSetProp(Instance: TObject; const PropInfo: PPropInfo; Brackets: Boolean): string;
  383. Procedure SetSetProp(Instance: TObject; const PropName: string; const Value: string);
  384. Procedure SetSetProp(Instance: TObject; const PropInfo: PPropInfo; const Value: string);
  385. Function GetStrProp(Instance: TObject; PropInfo : PPropInfo) : Ansistring;
  386. Function GetStrProp(Instance: TObject; const PropName: string): string;
  387. Procedure SetStrProp(Instance: TObject; const PropName: string; const Value: AnsiString);
  388. Procedure SetStrProp(Instance: TObject; PropInfo : PPropInfo; const Value : Ansistring);
  389. Function GetWideStrProp(Instance: TObject; PropInfo: PPropInfo): WideString;
  390. Function GetWideStrProp(Instance: TObject; const PropName: string): WideString;
  391. Procedure SetWideStrProp(Instance: TObject; const PropName: string; const Value: WideString);
  392. Procedure SetWideStrProp(Instance: TObject; PropInfo: PPropInfo; const Value: WideString);
  393. Function GetUnicodeStrProp(Instance: TObject; PropInfo: PPropInfo): UnicodeString;
  394. Function GetUnicodeStrProp(Instance: TObject; const PropName: string): UnicodeString;
  395. Procedure SetUnicodeStrProp(Instance: TObject; const PropName: string; const Value: UnicodeString);
  396. Procedure SetUnicodeStrProp(Instance: TObject; PropInfo: PPropInfo; const Value: UnicodeString);
  397. {$ifndef FPUNONE}
  398. Function GetFloatProp(Instance: TObject; PropInfo : PPropInfo) : Extended;
  399. Function GetFloatProp(Instance: TObject; const PropName: string): Extended;
  400. Procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Extended);
  401. Procedure SetFloatProp(Instance: TObject; PropInfo : PPropInfo; Value : Extended);
  402. {$endif}
  403. Function GetObjectProp(Instance: TObject; const PropName: string): TObject;
  404. Function GetObjectProp(Instance: TObject; const PropName: string; MinClass: TClass): TObject;
  405. Function GetObjectProp(Instance: TObject; PropInfo: PPropInfo): TObject;
  406. Function GetObjectProp(Instance: TObject; PropInfo: PPropInfo; MinClass: TClass): TObject;
  407. Procedure SetObjectProp(Instance: TObject; const PropName: string; Value: TObject);
  408. Procedure SetObjectProp(Instance: TObject; PropInfo: PPropInfo; Value: TObject);
  409. Function GetObjectPropClass(Instance: TObject; const PropName: string): TClass;
  410. Function GetObjectPropClass(AClass: TClass; const PropName: string): TClass;
  411. Function GetMethodProp(Instance: TObject; PropInfo: PPropInfo) : TMethod;
  412. Function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
  413. Procedure SetMethodProp(Instance: TObject; PropInfo: PPropInfo; const Value : TMethod);
  414. Procedure SetMethodProp(Instance: TObject; const PropName: string; const Value: TMethod);
  415. Function GetInt64Prop(Instance: TObject; PropInfo: PPropInfo): Int64;
  416. Function GetInt64Prop(Instance: TObject; const PropName: string): Int64;
  417. Procedure SetInt64Prop(Instance: TObject; PropInfo: PPropInfo; const Value: Int64);
  418. Procedure SetInt64Prop(Instance: TObject; const PropName: string; const Value: Int64);
  419. Function GetPropValue(Instance: TObject; const PropName: string): Variant;
  420. Function GetPropValue(Instance: TObject; const PropName: string; PreferStrings: Boolean): Variant;
  421. Function GetPropValue(Instance: TObject; PropInfo: PPropInfo): Variant;
  422. Function GetPropValue(Instance: TObject; PropInfo: PPropInfo; PreferStrings: Boolean): Variant;
  423. Procedure SetPropValue(Instance: TObject; const PropName: string; const Value: Variant);
  424. Procedure SetPropValue(Instance: TObject; PropInfo: PPropInfo; const Value: Variant);
  425. Function GetVariantProp(Instance: TObject; PropInfo : PPropInfo): Variant;
  426. Function GetVariantProp(Instance: TObject; const PropName: string): Variant;
  427. Procedure SetVariantProp(Instance: TObject; const PropName: string; const Value: Variant);
  428. Procedure SetVariantProp(Instance: TObject; PropInfo : PPropInfo; const Value: Variant);
  429. function GetInterfaceProp(Instance: TObject; const PropName: string): IInterface;
  430. function GetInterfaceProp(Instance: TObject; PropInfo: PPropInfo): IInterface;
  431. procedure SetInterfaceProp(Instance: TObject; const PropName: string; const Value: IInterface);
  432. procedure SetInterfaceProp(Instance: TObject; PropInfo: PPropInfo; const Value: IInterface);
  433. function GetRawInterfaceProp(Instance: TObject; const PropName: string): Pointer;
  434. function GetRawInterfaceProp(Instance: TObject; PropInfo: PPropInfo): Pointer;
  435. procedure SetRawInterfaceProp(Instance: TObject; const PropName: string; const Value: Pointer);
  436. procedure SetRawInterfaceProp(Instance: TObject; PropInfo: PPropInfo; const Value: Pointer);
  437. // Auxiliary routines, which may be useful
  438. Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
  439. Function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
  440. function GetEnumNameCount(enum1: PTypeInfo): SizeInt;
  441. function SetToString(TypeInfo: PTypeInfo; Value: Integer; Brackets: Boolean) : String;
  442. function SetToString(PropInfo: PPropInfo; Value: Integer; Brackets: Boolean) : String;
  443. function SetToString(PropInfo: PPropInfo; Value: Integer) : String;
  444. function StringToSet(PropInfo: PPropInfo; const Value: string): Integer;
  445. function StringToSet(TypeInfo: PTypeInfo; const Value: string): Integer;
  446. const
  447. BooleanIdents: array[Boolean] of String = ('False', 'True');
  448. DotSep: String = '.';
  449. Type
  450. EPropertyError = Class(Exception);
  451. TGetPropValue = Function (Instance: TObject; PropInfo: PPropInfo; PreferStrings: Boolean) : Variant;
  452. TSetPropValue = Procedure (Instance: TObject; PropInfo: PPropInfo; const Value: Variant);
  453. TGetVariantProp = Function (Instance: TObject; PropInfo : PPropInfo): Variant;
  454. TSetVariantProp = Procedure (Instance: TObject; PropInfo : PPropInfo; const Value: Variant);
  455. EPropertyConvertError = class(Exception); // Not used (yet), but defined for compatibility.
  456. Const
  457. OnGetPropValue : TGetPropValue = Nil;
  458. OnSetPropValue : TSetPropValue = Nil;
  459. OnGetVariantprop : TGetVariantProp = Nil;
  460. OnSetVariantprop : TSetVariantProp = Nil;
  461. { for inlining }
  462. function DerefTypeInfoPtr(Info: TypeInfoPtr): PTypeInfo; inline;
  463. Implementation
  464. uses rtlconsts;
  465. type
  466. PMethod = ^TMethod;
  467. { ---------------------------------------------------------------------
  468. Auxiliary methods
  469. ---------------------------------------------------------------------}
  470. function aligntoptr(p : pointer) : pointer;inline;
  471. begin
  472. {$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
  473. result:=align(p,sizeof(p));
  474. {$else FPC_REQUIRES_PROPER_ALIGNMENT}
  475. result:=p;
  476. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  477. end;
  478. function DerefTypeInfoPtr(Info: TypeInfoPtr): PTypeInfo; inline;
  479. begin
  480. {$ifdef ver3_0}
  481. Result := Info;
  482. {$else}
  483. if not Assigned(Info) then
  484. Result := Nil
  485. else
  486. Result := Info^;
  487. {$endif}
  488. end;
  489. Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
  490. Var PS : PShortString;
  491. PT : PTypeData;
  492. begin
  493. PT:=GetTypeData(TypeInfo);
  494. if TypeInfo^.Kind=tkBool then
  495. begin
  496. case Value of
  497. 0,1:
  498. Result:=BooleanIdents[Boolean(Value)];
  499. else
  500. Result:='';
  501. end;
  502. end
  503. else
  504. begin
  505. PS:=@PT^.NameList;
  506. dec(Value,PT^.MinValue);
  507. While Value>0 Do
  508. begin
  509. PS:=PShortString(pointer(PS)+PByte(PS)^+1);
  510. Dec(Value);
  511. end;
  512. Result:=PS^;
  513. end;
  514. end;
  515. Function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
  516. Var PS : PShortString;
  517. PT : PTypeData;
  518. Count : longint;
  519. sName: shortstring;
  520. begin
  521. If Length(Name)=0 then
  522. exit(-1);
  523. sName := Name;
  524. PT:=GetTypeData(TypeInfo);
  525. Count:=0;
  526. Result:=-1;
  527. if TypeInfo^.Kind=tkBool then
  528. begin
  529. If CompareText(BooleanIdents[false],Name)=0 then
  530. result:=0
  531. else if CompareText(BooleanIdents[true],Name)=0 then
  532. result:=1;
  533. end
  534. else
  535. begin
  536. PS:=@PT^.NameList;
  537. While (Result=-1) and (PByte(PS)^<>0) do
  538. begin
  539. If ShortCompareText(PS^, sName) = 0 then
  540. Result:=Count+PT^.MinValue;
  541. PS:=PShortString(pointer(PS)+PByte(PS)^+1);
  542. Inc(Count);
  543. end;
  544. end;
  545. end;
  546. function GetEnumNameCount(enum1: PTypeInfo): SizeInt;
  547. var
  548. PS: PShortString;
  549. PT: PTypeData;
  550. Count: SizeInt;
  551. begin
  552. PT:=GetTypeData(enum1);
  553. if enum1^.Kind=tkBool then
  554. Result:=2
  555. else
  556. begin
  557. Count:=0;
  558. Result:=0;
  559. PS:=@PT^.NameList;
  560. While (PByte(PS)^<>0) do
  561. begin
  562. PS:=PShortString(pointer(PS)+PByte(PS)^+1);
  563. Inc(Count);
  564. end;
  565. { the last string is the unit name }
  566. Result := Count - 1;
  567. end;
  568. end;
  569. Function SetToString(PropInfo: PPropInfo; Value: Integer; Brackets: Boolean) : String;
  570. begin
  571. Result:=SetToString(PropInfo^.PropType,Value,Brackets);
  572. end;
  573. Function SetToString(TypeInfo: PTypeInfo; Value: Integer; Brackets: Boolean) : String;
  574. type
  575. tsetarr = bitpacked array[0..SizeOf(Integer)*8-1] of 0..1;
  576. Var
  577. I : Integer;
  578. PTI : PTypeInfo;
  579. begin
  580. {$if defined(FPC_BIG_ENDIAN)}
  581. { On big endian systems, set element 0 is in the most significant bit,
  582. and the same goes for the elements of bitpacked arrays there. }
  583. case GetTypeData(TypeInfo)^.OrdType of
  584. otSByte,otUByte: Value:=Value shl (SizeOf(Integer)*8-8);
  585. otSWord,otUWord: Value:=Value shl (SizeOf(Integer)*8-16);
  586. end;
  587. {$endif}
  588. PTI:=GetTypeData(TypeInfo)^.CompType;
  589. Result:='';
  590. For I:=0 to SizeOf(Integer)*8-1 do
  591. begin
  592. if (tsetarr(Value)[i]<>0) then
  593. begin
  594. If Result='' then
  595. Result:=GetEnumName(PTI,i)
  596. else
  597. Result:=Result+','+GetEnumName(PTI,I);
  598. end;
  599. end;
  600. if Brackets then
  601. Result:='['+Result+']';
  602. end;
  603. Function SetToString(PropInfo: PPropInfo; Value: Integer) : String;
  604. begin
  605. Result:=SetToString(PropInfo,Value,False);
  606. end;
  607. Const
  608. SetDelim = ['[',']',',',' '];
  609. Function GetNextElement(Var S : String) : String;
  610. Var
  611. J : Integer;
  612. begin
  613. J:=1;
  614. Result:='';
  615. If Length(S)>0 then
  616. begin
  617. While (J<=Length(S)) and Not (S[j] in SetDelim) do
  618. Inc(j);
  619. Result:=Copy(S,1,j-1);
  620. Delete(S,1,j);
  621. end;
  622. end;
  623. Function StringToSet(PropInfo: PPropInfo; const Value: string): Integer;
  624. begin
  625. Result:=StringToSet(PropInfo^.PropType,Value);
  626. end;
  627. Function StringToSet(TypeInfo: PTypeInfo; const Value: string): Integer;
  628. Var
  629. S,T : String;
  630. I : Integer;
  631. PTI : PTypeInfo;
  632. begin
  633. Result:=0;
  634. PTI:=GetTypeData(TypeInfo)^.Comptype;
  635. S:=Value;
  636. I:=1;
  637. If Length(S)>0 then
  638. begin
  639. While (I<=Length(S)) and (S[i] in SetDelim) do
  640. Inc(I);
  641. Delete(S,1,i-1);
  642. end;
  643. While (S<>'') do
  644. begin
  645. T:=GetNextElement(S);
  646. if T<>'' then
  647. begin
  648. I:=GetEnumValue(PTI,T);
  649. if (I<0) then
  650. raise EPropertyError.CreateFmt(SErrUnknownEnumValue, [T]);
  651. Result:=Result or (1 shl i);
  652. end;
  653. end;
  654. end;
  655. Function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
  656. begin
  657. GetTypeData:=PTypeData(aligntoptr(PTypeData(pointer(TypeInfo)+2+PByte(pointer(TypeInfo)+1)^)));
  658. end;
  659. { ---------------------------------------------------------------------
  660. Basic Type information functions.
  661. ---------------------------------------------------------------------}
  662. Function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string) : PPropInfo;
  663. var
  664. hp : PTypeData;
  665. i : longint;
  666. p : shortstring;
  667. pd : ^TPropData;
  668. begin
  669. P:=PropName; // avoid Ansi<->short conversion in a loop
  670. while Assigned(TypeInfo) do
  671. begin
  672. // skip the name
  673. hp:=GetTypeData(Typeinfo);
  674. // the class info rtti the property rtti follows immediatly
  675. pd:=aligntoptr(pointer(pointer(@hp^.UnitName)+Length(hp^.UnitName)+1));
  676. Result:=PPropInfo(@pd^.PropList);
  677. for i:=1 to pd^.PropCount do
  678. begin
  679. // found a property of that name ?
  680. if ShortCompareText(Result^.Name, P) = 0 then
  681. exit;
  682. // skip to next property
  683. Result:=PPropInfo(aligntoptr(pointer(@Result^.Name)+byte(Result^.Name[0])+1));
  684. end;
  685. // parent class
  686. Typeinfo:=hp^.ParentInfo;
  687. end;
  688. Result:=Nil;
  689. end;
  690. Function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string; Akinds : TTypeKinds) : PPropInfo;
  691. begin
  692. Result:=GetPropInfo(TypeInfo,PropName);
  693. If (Akinds<>[]) then
  694. If (Result<>Nil) then
  695. If Not (Result^.PropType^.Kind in AKinds) then
  696. Result:=Nil;
  697. end;
  698. Function GetPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  699. begin
  700. Result:=GetPropInfo(PTypeInfo(AClass.ClassInfo),PropName,AKinds);
  701. end;
  702. Function GetPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  703. begin
  704. Result:=GetPropInfo(Instance.ClassType,PropName,AKinds);
  705. end;
  706. Function GetPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  707. begin
  708. Result:=GetPropInfo(Instance,PropName,[]);
  709. end;
  710. Function GetPropInfo(AClass: TClass; const PropName: string): PPropInfo;
  711. begin
  712. Result:=GetPropInfo(AClass,PropName,[]);
  713. end;
  714. Function FindPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  715. begin
  716. result:=GetPropInfo(Instance, PropName);
  717. if Result=nil then
  718. Raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
  719. end;
  720. Function FindPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds): PPropInfo;
  721. begin
  722. result:=GetPropInfo(Instance, PropName, AKinds);
  723. if Result=nil then
  724. Raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
  725. end;
  726. Function FindPropInfo(AClass: TClass; const PropName: string): PPropInfo;
  727. begin
  728. result:=GetPropInfo(AClass, PropName);
  729. if result=nil then
  730. Raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
  731. end;
  732. Function FindPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds): PPropInfo;
  733. begin
  734. result:=GetPropInfo(AClass, PropName, AKinds);
  735. if result=nil then
  736. Raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
  737. end;
  738. Function IsStoredProp(Instance : TObject;PropInfo : PPropInfo) : Boolean;
  739. type
  740. TBooleanIndexFunc=function(Index:integer):boolean of object;
  741. TBooleanFunc=function:boolean of object;
  742. var
  743. AMethod : TMethod;
  744. begin
  745. case (PropInfo^.PropProcs shr 4) and 3 of
  746. ptField:
  747. Result:=PBoolean(Pointer(Instance)+PtrUInt(PropInfo^.StoredProc))^;
  748. ptConst:
  749. Result:=LongBool(PropInfo^.StoredProc);
  750. ptStatic,
  751. ptVirtual:
  752. begin
  753. if (PropInfo^.PropProcs shr 4) and 3=ptstatic then
  754. AMethod.Code:=PropInfo^.StoredProc
  755. else
  756. AMethod.Code:=pcodepointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.StoredProc))^;
  757. AMethod.Data:=Instance;
  758. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  759. Result:=TBooleanIndexFunc(AMethod)(PropInfo^.Index)
  760. else
  761. Result:=TBooleanFunc(AMethod)();
  762. end;
  763. end;
  764. end;
  765. Procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
  766. {
  767. Store Pointers to property information in the list pointed
  768. to by proplist. PRopList must contain enough space to hold ALL
  769. properties.
  770. }
  771. Var
  772. TD : PTypeData;
  773. TP : PPropInfo;
  774. Count : Longint;
  775. begin
  776. // Get this objects TOTAL published properties count
  777. TD:=GetTypeData(TypeInfo);
  778. // Clear list
  779. FillChar(PropList^,TD^.PropCount*sizeof(Pointer),0);
  780. repeat
  781. TD:=GetTypeData(TypeInfo);
  782. // published properties count for this object
  783. TP:=aligntoptr(PPropInfo(aligntoptr((Pointer(@TD^.UnitName)+Length(TD^.UnitName)+1))));
  784. Count:=PWord(TP)^;
  785. // Now point TP to first propinfo record.
  786. Inc(Pointer(TP),SizeOF(Word));
  787. tp:=aligntoptr(tp);
  788. While Count>0 do
  789. begin
  790. // Don't overwrite properties with the same name
  791. if PropList^[TP^.NameIndex]=nil then
  792. PropList^[TP^.NameIndex]:=TP;
  793. // Point to TP next propinfo record.
  794. // Located at Name[Length(Name)+1] !
  795. TP:=aligntoptr(PPropInfo(pointer(@TP^.Name)+PByte(@TP^.Name)^+1));
  796. Dec(Count);
  797. end;
  798. TypeInfo:=TD^.Parentinfo;
  799. until TypeInfo=nil;
  800. end;
  801. Procedure InsertProp (PL : PProplist;PI : PPropInfo; Count : longint);
  802. Var
  803. I : Longint;
  804. begin
  805. I:=0;
  806. While (I<Count) and (PI^.Name>PL^[I]^.Name) do
  807. Inc(I);
  808. If I<Count then
  809. Move(PL^[I], PL^[I+1], (Count - I) * SizeOf(Pointer));
  810. PL^[I]:=PI;
  811. end;
  812. Procedure InsertPropnosort (PL : PProplist;PI : PPropInfo; Count : longint);
  813. begin
  814. PL^[Count]:=PI;
  815. end;
  816. Type TInsertProp = Procedure (PL : PProplist;PI : PPropInfo; Count : longint);
  817. //Const InsertProps : array[false..boolean] of TInsertProp = (InsertPropNoSort,InsertProp);
  818. Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds; PropList : PPropList;Sorted : boolean = true):longint;
  819. {
  820. Store Pointers to property information OF A CERTAIN KIND in the list pointed
  821. to by proplist. PRopList must contain enough space to hold ALL
  822. properties.
  823. }
  824. Var
  825. TempList : PPropList;
  826. PropInfo : PPropinfo;
  827. I,Count : longint;
  828. DoInsertProp : TInsertProp;
  829. begin
  830. if sorted then
  831. DoInsertProp:=@InsertProp
  832. else
  833. DoInsertProp:=@InsertPropnosort;
  834. Result:=0;
  835. Count:=GetTypeData(TypeInfo)^.Propcount;
  836. If Count>0 then
  837. begin
  838. GetMem(TempList,Count*SizeOf(Pointer));
  839. Try
  840. GetPropInfos(TypeInfo,TempList);
  841. For I:=0 to Count-1 do
  842. begin
  843. PropInfo:=TempList^[i];
  844. If PropInfo^.PropType^.Kind in TypeKinds then
  845. begin
  846. If (PropList<>Nil) then
  847. DoInsertProp(PropList,PropInfo,Result);
  848. Inc(Result);
  849. end;
  850. end;
  851. finally
  852. FreeMem(TempList,Count*SizeOf(Pointer));
  853. end;
  854. end;
  855. end;
  856. Function GetPropList(TypeInfo: PTypeInfo; out PropList: PPropList): SizeInt;
  857. begin
  858. result:=GetTypeData(TypeInfo)^.Propcount;
  859. if result>0 then
  860. begin
  861. getmem(PropList,result*sizeof(pointer));
  862. GetPropInfos(TypeInfo,PropList);
  863. end
  864. else
  865. PropList:=Nil;
  866. end;
  867. function GetPropList(AClass: TClass; out PropList: PPropList): Integer;
  868. begin
  869. Result := GetPropList(PTypeInfo(AClass.ClassInfo), PropList);
  870. end;
  871. function GetPropList(Instance: TObject; out PropList: PPropList): Integer;
  872. begin
  873. Result := GetPropList(Instance.ClassType, PropList);
  874. end;
  875. { ---------------------------------------------------------------------
  876. Property access functions
  877. ---------------------------------------------------------------------}
  878. { ---------------------------------------------------------------------
  879. Ordinal properties
  880. ---------------------------------------------------------------------}
  881. Function GetOrdProp(Instance : TObject;PropInfo : PPropInfo) : Int64;
  882. type
  883. TGetInt64ProcIndex=function(index:longint):Int64 of object;
  884. TGetInt64Proc=function():Int64 of object;
  885. TGetIntegerProcIndex=function(index:longint):longint of object;
  886. TGetIntegerProc=function:longint of object;
  887. TGetWordProcIndex=function(index:longint):word of object;
  888. TGetWordProc=function:word of object;
  889. TGetByteProcIndex=function(index:longint):Byte of object;
  890. TGetByteProc=function:Byte of object;
  891. var
  892. TypeInfo: PTypeInfo;
  893. AMethod : TMethod;
  894. DataSize: Integer;
  895. OrdType: TOrdType;
  896. Signed: Boolean;
  897. begin
  898. Result:=0;
  899. TypeInfo := PropInfo^.PropType;
  900. Signed := false;
  901. DataSize := 4;
  902. case TypeInfo^.Kind of
  903. {$ifdef cpu64}
  904. tkInterface,
  905. tkInterfaceRaw,
  906. tkDynArray,
  907. tkClass:
  908. DataSize:=8;
  909. {$endif cpu64}
  910. tkChar, tkBool:
  911. DataSize:=1;
  912. tkWChar:
  913. DataSize:=2;
  914. tkSet,
  915. tkEnumeration,
  916. tkInteger:
  917. begin
  918. OrdType:=GetTypeData(TypeInfo)^.OrdType;
  919. case OrdType of
  920. otSByte,otUByte: DataSize := 1;
  921. otSWord,otUWord: DataSize := 2;
  922. end;
  923. Signed := OrdType in [otSByte,otSWord,otSLong];
  924. end;
  925. tkInt64 :
  926. begin
  927. DataSize:=8;
  928. Signed:=true;
  929. end;
  930. tkQword :
  931. begin
  932. DataSize:=8;
  933. Signed:=false;
  934. end;
  935. end;
  936. case (PropInfo^.PropProcs) and 3 of
  937. ptField:
  938. if Signed then begin
  939. case DataSize of
  940. 1: Result:=PShortInt(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  941. 2: Result:=PSmallInt(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  942. 4: Result:=PLongint(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  943. 8: Result:=PInt64(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  944. end;
  945. end else begin
  946. case DataSize of
  947. 1: Result:=PByte(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  948. 2: Result:=PWord(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  949. 4: Result:=PLongint(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  950. 8: Result:=PInt64(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  951. end;
  952. end;
  953. ptStatic,
  954. ptVirtual:
  955. begin
  956. if (PropInfo^.PropProcs and 3)=ptStatic then
  957. AMethod.Code:=PropInfo^.GetProc
  958. else
  959. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;
  960. AMethod.Data:=Instance;
  961. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then begin
  962. case DataSize of
  963. 1: Result:=TGetByteProcIndex(AMethod)(PropInfo^.Index);
  964. 2: Result:=TGetWordProcIndex(AMethod)(PropInfo^.Index);
  965. 4: Result:=TGetIntegerProcIndex(AMethod)(PropInfo^.Index);
  966. 8: result:=TGetInt64ProcIndex(AMethod)(PropInfo^.Index)
  967. end;
  968. end else begin
  969. case DataSize of
  970. 1: Result:=TGetByteProc(AMethod)();
  971. 2: Result:=TGetWordProc(AMethod)();
  972. 4: Result:=TGetIntegerProc(AMethod)();
  973. 8: result:=TGetInt64Proc(AMethod)();
  974. end;
  975. end;
  976. if Signed then begin
  977. case DataSize of
  978. 1: Result:=ShortInt(Result);
  979. 2: Result:=SmallInt(Result);
  980. end;
  981. end;
  982. end;
  983. end;
  984. end;
  985. Procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;Value : Int64);
  986. type
  987. TSetInt64ProcIndex=procedure(index:longint;i:Int64) of object;
  988. TSetInt64Proc=procedure(i:Int64) of object;
  989. TSetIntegerProcIndex=procedure(index,i:longint) of object;
  990. TSetIntegerProc=procedure(i:longint) of object;
  991. var
  992. DataSize: Integer;
  993. AMethod : TMethod;
  994. begin
  995. if PropInfo^.PropType^.Kind in [tkInt64,tkQword
  996. { why do we have to handle classes here, see also below? (FK) }
  997. {$ifdef cpu64}
  998. ,tkInterface
  999. ,tkInterfaceRaw
  1000. ,tkDynArray
  1001. ,tkClass
  1002. {$endif cpu64}
  1003. ] then
  1004. DataSize := 8
  1005. else
  1006. DataSize := 4;
  1007. if not(PropInfo^.PropType^.Kind in [tkInt64,tkQword,tkClass,tkInterface,tkInterfaceRaw,tkDynArray]) then
  1008. begin
  1009. { cut off unnecessary stuff }
  1010. case GetTypeData(PropInfo^.PropType)^.OrdType of
  1011. otSWord,otUWord:
  1012. begin
  1013. Value:=Value and $ffff;
  1014. DataSize := 2;
  1015. end;
  1016. otSByte,otUByte:
  1017. begin
  1018. Value:=Value and $ff;
  1019. DataSize := 1;
  1020. end;
  1021. end;
  1022. end;
  1023. case (PropInfo^.PropProcs shr 2) and 3 of
  1024. ptField:
  1025. case DataSize of
  1026. 1: PByte(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Byte(Value);
  1027. 2: PWord(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Word(Value);
  1028. 4: PLongint(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Longint(Value);
  1029. 8: PInt64(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1030. end;
  1031. ptStatic,
  1032. ptVirtual:
  1033. begin
  1034. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1035. AMethod.Code:=PropInfo^.SetProc
  1036. else
  1037. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1038. AMethod.Data:=Instance;
  1039. if datasize=8 then
  1040. begin
  1041. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1042. TSetInt64ProcIndex(AMethod)(PropInfo^.Index,Value)
  1043. else
  1044. TSetInt64Proc(AMethod)(Value);
  1045. end
  1046. else
  1047. begin
  1048. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1049. TSetIntegerProcIndex(AMethod)(PropInfo^.Index,Value)
  1050. else
  1051. TSetIntegerProc(AMethod)(Value);
  1052. end;
  1053. end;
  1054. end;
  1055. end;
  1056. Function GetOrdProp(Instance: TObject; const PropName: string): Int64;
  1057. begin
  1058. Result:=GetOrdProp(Instance,FindPropInfo(Instance,PropName));
  1059. end;
  1060. Procedure SetOrdProp(Instance: TObject; const PropName: string; Value: Int64);
  1061. begin
  1062. SetOrdProp(Instance,FindPropInfo(Instance,PropName),Value);
  1063. end;
  1064. Function GetEnumProp(Instance: TObject; Const PropInfo: PPropInfo): string;
  1065. begin
  1066. Result:=GetEnumName(PropInfo^.PropType, GetOrdProp(Instance, PropInfo));
  1067. end;
  1068. Function GetEnumProp(Instance: TObject; const PropName: string): string;
  1069. begin
  1070. Result:=GetEnumProp(Instance,FindPropInfo(Instance,PropName));
  1071. end;
  1072. Procedure SetEnumProp(Instance: TObject; const PropName: string; const Value: string);
  1073. begin
  1074. SetEnumProp(Instance,FindPropInfo(Instance,PropName),Value);
  1075. end;
  1076. Procedure SetEnumProp(Instance: TObject; Const PropInfo : PPropInfo; const Value: string);
  1077. Var
  1078. PV : Longint;
  1079. begin
  1080. If PropInfo<>Nil then
  1081. begin
  1082. PV:=GetEnumValue(PropInfo^.PropType, Value);
  1083. if (PV<0) then
  1084. raise EPropertyError.CreateFmt(SErrUnknownEnumValue, [Value]);
  1085. SetOrdProp(Instance, PropInfo,PV);
  1086. end;
  1087. end;
  1088. { ---------------------------------------------------------------------
  1089. Int64 wrappers
  1090. ---------------------------------------------------------------------}
  1091. Function GetInt64Prop(Instance: TObject; PropInfo: PPropInfo): Int64;
  1092. begin
  1093. Result:=GetOrdProp(Instance,PropInfo);
  1094. end;
  1095. procedure SetInt64Prop(Instance: TObject; PropInfo: PPropInfo; const Value: Int64);
  1096. begin
  1097. SetOrdProp(Instance,PropInfo,Value);
  1098. end;
  1099. Function GetInt64Prop(Instance: TObject; const PropName: string): Int64;
  1100. begin
  1101. Result:=GetInt64Prop(Instance,FindPropInfo(Instance,PropName));
  1102. end;
  1103. Procedure SetInt64Prop(Instance: TObject; const PropName: string; const Value: Int64);
  1104. begin
  1105. SetInt64Prop(Instance,FindPropInfo(Instance,PropName),Value);
  1106. end;
  1107. { ---------------------------------------------------------------------
  1108. Set properties
  1109. ---------------------------------------------------------------------}
  1110. Function GetSetProp(Instance: TObject; const PropName: string): string;
  1111. begin
  1112. Result:=GetSetProp(Instance,PropName,False);
  1113. end;
  1114. Function GetSetProp(Instance: TObject; const PropName: string; Brackets: Boolean): string;
  1115. begin
  1116. Result:=GetSetProp(Instance,FindPropInfo(Instance,PropName),Brackets);
  1117. end;
  1118. Function GetSetProp(Instance: TObject; const PropInfo: PPropInfo; Brackets: Boolean): string;
  1119. begin
  1120. Result:=SetToString(PropInfo,GetOrdProp(Instance,PropInfo),Brackets);
  1121. end;
  1122. Procedure SetSetProp(Instance: TObject; const PropName: string; const Value: string);
  1123. begin
  1124. SetSetProp(Instance,FindPropInfo(Instance,PropName),Value);
  1125. end;
  1126. Procedure SetSetProp(Instance: TObject; const PropInfo: PPropInfo; const Value: string);
  1127. begin
  1128. SetOrdProp(Instance,PropInfo,StringToSet(PropInfo,Value));
  1129. end;
  1130. { ---------------------------------------------------------------------
  1131. Object properties
  1132. ---------------------------------------------------------------------}
  1133. Function GetObjectProp(Instance: TObject; const PropName: string): TObject;
  1134. begin
  1135. Result:=GetObjectProp(Instance,PropName,Nil);
  1136. end;
  1137. Function GetObjectProp(Instance: TObject; const PropName: string; MinClass: TClass): TObject;
  1138. begin
  1139. Result:=GetObjectProp(Instance,FindPropInfo(Instance,PropName),MinClass);
  1140. end;
  1141. Function GetObjectProp(Instance: TObject; PropInfo : PPropInfo): TObject;
  1142. begin
  1143. Result:=GetObjectProp(Instance,PropInfo,Nil);
  1144. end;
  1145. Function GetObjectProp(Instance: TObject; PropInfo : PPropInfo; MinClass: TClass): TObject;
  1146. begin
  1147. {$ifdef cpu64}
  1148. Result:=TObject(GetInt64Prop(Instance,PropInfo));
  1149. {$else cpu64}
  1150. Result:=TObject(PtrInt(GetOrdProp(Instance,PropInfo)));
  1151. {$endif cpu64}
  1152. If (MinClass<>Nil) and (Result<>Nil) Then
  1153. If Not Result.InheritsFrom(MinClass) then
  1154. Result:=Nil;
  1155. end;
  1156. Procedure SetObjectProp(Instance: TObject; const PropName: string; Value: TObject);
  1157. begin
  1158. SetObjectProp(Instance,FindPropInfo(Instance,PropName),Value);
  1159. end;
  1160. Procedure SetObjectProp(Instance: TObject; PropInfo : PPropInfo; Value: TObject);
  1161. begin
  1162. {$ifdef cpu64}
  1163. SetInt64Prop(Instance,PropInfo,Int64(Value));
  1164. {$else cpu64}
  1165. SetOrdProp(Instance,PropInfo,PtrInt(Value));
  1166. {$endif cpu64}
  1167. end;
  1168. Function GetObjectPropClass(Instance: TObject; const PropName: string): TClass;
  1169. begin
  1170. Result:=GetTypeData(FindPropInfo(Instance,PropName,[tkClass])^.PropType)^.ClassType;
  1171. end;
  1172. Function GetObjectPropClass(AClass: TClass; const PropName: string): TClass;
  1173. begin
  1174. Result:=GetTypeData(FindPropInfo(AClass,PropName,[tkClass])^.PropType)^.ClassType;
  1175. end;
  1176. { ---------------------------------------------------------------------
  1177. Interface wrapprers
  1178. ---------------------------------------------------------------------}
  1179. function GetInterfaceProp(Instance: TObject; const PropName: string): IInterface;
  1180. begin
  1181. Result:=GetInterfaceProp(Instance,FindPropInfo(Instance,PropName));
  1182. end;
  1183. function GetInterfaceProp(Instance: TObject; PropInfo: PPropInfo): IInterface;
  1184. type
  1185. TGetInterfaceProc=function:IInterface of object;
  1186. TGetInterfaceProcIndex=function(index:longint):IInterface of object;
  1187. var
  1188. TypeInfo: PTypeInfo;
  1189. AMethod : TMethod;
  1190. begin
  1191. Result:=nil;
  1192. TypeInfo := PropInfo^.PropType;
  1193. case (PropInfo^.PropProcs) and 3 of
  1194. ptField:
  1195. Result:=IInterface(PPointer(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^);
  1196. ptStatic,
  1197. ptVirtual:
  1198. begin
  1199. if (PropInfo^.PropProcs and 3)=ptStatic then
  1200. AMethod.Code:=PropInfo^.GetProc
  1201. else
  1202. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;
  1203. AMethod.Data:=Instance;
  1204. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1205. Result:=TGetInterfaceProcIndex(AMethod)(PropInfo^.Index)
  1206. else
  1207. Result:=TGetInterfaceProc(AMethod)();
  1208. end;
  1209. end;
  1210. end;
  1211. procedure SetInterfaceProp(Instance: TObject; const PropName: string; const Value: IInterface);
  1212. begin
  1213. SetInterfaceProp(Instance,FindPropInfo(Instance,PropName),Value);
  1214. end;
  1215. procedure SetInterfaceProp(Instance: TObject; PropInfo: PPropInfo; const Value: IInterface);
  1216. type
  1217. TSetIntfStrProcIndex=procedure(index:longint;const i:IInterface) of object;
  1218. TSetIntfStrProc=procedure(i:IInterface) of object;
  1219. var
  1220. AMethod : TMethod;
  1221. begin
  1222. case Propinfo^.PropType^.Kind of
  1223. tkInterface:
  1224. begin
  1225. case (PropInfo^.PropProcs shr 2) and 3 of
  1226. ptField:
  1227. PInterface(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1228. ptStatic,
  1229. ptVirtual:
  1230. begin
  1231. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1232. AMethod.Code:=PropInfo^.SetProc
  1233. else
  1234. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1235. AMethod.Data:=Instance;
  1236. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1237. TSetIntfStrProcIndex(AMethod)(PropInfo^.Index,Value)
  1238. else
  1239. TSetIntfStrProc(AMethod)(Value);
  1240. end;
  1241. end;
  1242. end;
  1243. tkInterfaceRaw:
  1244. Raise Exception.Create('Cannot set RAW interface from IUnknown interface');
  1245. end;
  1246. end;
  1247. { ---------------------------------------------------------------------
  1248. RAW (Corba) Interface wrapprers
  1249. ---------------------------------------------------------------------}
  1250. function GetRawInterfaceProp(Instance: TObject; const PropName: string): Pointer;
  1251. begin
  1252. Result:=GetRawInterfaceProp(Instance,FindPropInfo(Instance,PropName));
  1253. end;
  1254. function GetRawInterfaceProp(Instance: TObject; PropInfo: PPropInfo): Pointer;
  1255. begin
  1256. {$ifdef cpu64}
  1257. Result:=Pointer(GetInt64Prop(Instance,PropInfo));
  1258. {$else cpu64}
  1259. Result:=Pointer(PtrInt(GetOrdProp(Instance,PropInfo)));
  1260. {$endif cpu64}
  1261. end;
  1262. procedure SetRawInterfaceProp(Instance: TObject; const PropName: string; const Value: Pointer);
  1263. begin
  1264. SetRawInterfaceProp(Instance,FindPropInfo(Instance,PropName),Value);
  1265. end;
  1266. procedure SetRawInterfaceProp(Instance: TObject; PropInfo: PPropInfo; const Value: Pointer);
  1267. type
  1268. TSetPointerProcIndex=procedure(index:longint;const i:Pointer) of object;
  1269. TSetPointerProc=procedure(i:Pointer) of object;
  1270. var
  1271. AMethod : TMethod;
  1272. begin
  1273. case Propinfo^.PropType^.Kind of
  1274. tkInterfaceRaw:
  1275. begin
  1276. case (PropInfo^.PropProcs shr 2) and 3 of
  1277. ptField:
  1278. PPointer(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1279. ptStatic,
  1280. ptVirtual:
  1281. begin
  1282. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1283. AMethod.Code:=PropInfo^.SetProc
  1284. else
  1285. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1286. AMethod.Data:=Instance;
  1287. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1288. TSetPointerProcIndex(AMethod)(PropInfo^.Index,Value)
  1289. else
  1290. TSetPointerProc(AMethod)(Value);
  1291. end;
  1292. end;
  1293. end;
  1294. tkInterface:
  1295. Raise Exception.Create('Cannot set interface from RAW interface');
  1296. end;
  1297. end;
  1298. { ---------------------------------------------------------------------
  1299. String properties
  1300. ---------------------------------------------------------------------}
  1301. Function GetStrProp(Instance: TObject; PropInfo: PPropInfo): AnsiString;
  1302. type
  1303. TGetShortStrProcIndex=function(index:longint):ShortString of object;
  1304. TGetShortStrProc=function():ShortString of object;
  1305. TGetAnsiStrProcIndex=function(index:longint):AnsiString of object;
  1306. TGetAnsiStrProc=function():AnsiString of object;
  1307. var
  1308. AMethod : TMethod;
  1309. begin
  1310. Result:='';
  1311. case Propinfo^.PropType^.Kind of
  1312. tkWString:
  1313. Result:=AnsiString(GetWideStrProp(Instance,PropInfo));
  1314. tkUString:
  1315. Result := AnsiString(GetUnicodeStrProp(Instance,PropInfo));
  1316. tkSString:
  1317. begin
  1318. case (PropInfo^.PropProcs) and 3 of
  1319. ptField:
  1320. Result := PShortString(Pointer(Instance) + LongWord(PropInfo^.GetProc))^;
  1321. ptStatic,
  1322. ptVirtual:
  1323. begin
  1324. if (PropInfo^.PropProcs and 3)=ptStatic then
  1325. AMethod.Code:=PropInfo^.GetProc
  1326. else
  1327. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;
  1328. AMethod.Data:=Instance;
  1329. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1330. Result:=TGetShortStrProcIndex(AMethod)(PropInfo^.Index)
  1331. else
  1332. Result:=TGetShortStrProc(AMethod)();
  1333. end;
  1334. end;
  1335. end;
  1336. tkAString:
  1337. begin
  1338. case (PropInfo^.PropProcs) and 3 of
  1339. ptField:
  1340. Result := PAnsiString(Pointer(Instance) + LongWord(PropInfo^.GetProc))^;
  1341. ptStatic,
  1342. ptVirtual:
  1343. begin
  1344. if (PropInfo^.PropProcs and 3)=ptStatic then
  1345. AMethod.Code:=PropInfo^.GetProc
  1346. else
  1347. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;
  1348. AMethod.Data:=Instance;
  1349. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1350. Result:=TGetAnsiStrProcIndex(AMethod)(PropInfo^.Index)
  1351. else
  1352. Result:=TGetAnsiStrProc(AMethod)();
  1353. end;
  1354. end;
  1355. end;
  1356. end;
  1357. end;
  1358. Procedure SetStrProp(Instance : TObject;PropInfo : PPropInfo; const Value : AnsiString);
  1359. type
  1360. TSetShortStrProcIndex=procedure(index:longint;const s:ShortString) of object;
  1361. TSetShortStrProc=procedure(const s:ShortString) of object;
  1362. TSetAnsiStrProcIndex=procedure(index:longint;s:AnsiString) of object;
  1363. TSetAnsiStrProc=procedure(s:AnsiString) of object;
  1364. var
  1365. AMethod : TMethod;
  1366. begin
  1367. case Propinfo^.PropType^.Kind of
  1368. tkWString:
  1369. SetWideStrProp(Instance,PropInfo,WideString(Value));
  1370. tkUString:
  1371. SetUnicodeStrProp(Instance,PropInfo,UnicodeString(Value));
  1372. tkSString:
  1373. begin
  1374. case (PropInfo^.PropProcs shr 2) and 3 of
  1375. ptField:
  1376. PShortString(Pointer(Instance) + LongWord(PropInfo^.SetProc))^:=Value;
  1377. ptStatic,
  1378. ptVirtual:
  1379. begin
  1380. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1381. AMethod.Code:=PropInfo^.SetProc
  1382. else
  1383. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1384. AMethod.Data:=Instance;
  1385. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1386. TSetShortStrProcIndex(AMethod)(PropInfo^.Index,Value)
  1387. else
  1388. TSetShortStrProc(AMethod)(Value);
  1389. end;
  1390. end;
  1391. end;
  1392. tkAString:
  1393. begin
  1394. case (PropInfo^.PropProcs shr 2) and 3 of
  1395. ptField:
  1396. PAnsiString(Pointer(Instance) + LongWord(PropInfo^.SetProc))^:=Value;
  1397. ptStatic,
  1398. ptVirtual:
  1399. begin
  1400. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1401. AMethod.Code:=PropInfo^.SetProc
  1402. else
  1403. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1404. AMethod.Data:=Instance;
  1405. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1406. TSetAnsiStrProcIndex(AMethod)(PropInfo^.Index,Value)
  1407. else
  1408. TSetAnsiStrProc(AMethod)(Value);
  1409. end;
  1410. end;
  1411. end;
  1412. end;
  1413. end;
  1414. Function GetStrProp(Instance: TObject; const PropName: string): string;
  1415. begin
  1416. Result:=GetStrProp(Instance,FindPropInfo(Instance,PropName));
  1417. end;
  1418. Procedure SetStrProp(Instance: TObject; const PropName: string; const Value: AnsiString);
  1419. begin
  1420. SetStrProp(Instance,FindPropInfo(Instance,PropName),Value);
  1421. end;
  1422. Function GetWideStrProp(Instance: TObject; const PropName: string): WideString;
  1423. begin
  1424. Result:=GetWideStrProp(Instance, FindPropInfo(Instance, PropName));
  1425. end;
  1426. procedure SetWideStrProp(Instance: TObject; const PropName: string; const Value: WideString);
  1427. begin
  1428. SetWideStrProp(Instance,FindPropInfo(Instance,PropName),Value);
  1429. end;
  1430. Function GetWideStrProp(Instance: TObject; PropInfo: PPropInfo): WideString;
  1431. type
  1432. TGetWideStrProcIndex=function(index:longint):WideString of object;
  1433. TGetWideStrProc=function():WideString of object;
  1434. var
  1435. AMethod : TMethod;
  1436. begin
  1437. Result:='';
  1438. case Propinfo^.PropType^.Kind of
  1439. tkSString,tkAString:
  1440. Result:=WideString(GetStrProp(Instance,PropInfo));
  1441. tkUString :
  1442. Result := GetUnicodeStrProp(Instance,PropInfo);
  1443. tkWString:
  1444. begin
  1445. case (PropInfo^.PropProcs) and 3 of
  1446. ptField:
  1447. Result := PWideString(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  1448. ptStatic,
  1449. ptVirtual:
  1450. begin
  1451. if (PropInfo^.PropProcs and 3)=ptStatic then
  1452. AMethod.Code:=PropInfo^.GetProc
  1453. else
  1454. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;
  1455. AMethod.Data:=Instance;
  1456. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1457. Result:=TGetWideStrProcIndex(AMethod)(PropInfo^.Index)
  1458. else
  1459. Result:=TGetWideStrProc(AMethod)();
  1460. end;
  1461. end;
  1462. end;
  1463. end;
  1464. end;
  1465. Procedure SetWideStrProp(Instance: TObject; PropInfo: PPropInfo; const Value: WideString);
  1466. type
  1467. TSetWideStrProcIndex=procedure(index:longint;s:WideString) of object;
  1468. TSetWideStrProc=procedure(s:WideString) of object;
  1469. var
  1470. AMethod : TMethod;
  1471. begin
  1472. case Propinfo^.PropType^.Kind of
  1473. tkSString,tkAString:
  1474. SetStrProp(Instance,PropInfo,AnsiString(Value));
  1475. tkUString:
  1476. SetUnicodeStrProp(Instance,PropInfo,Value);
  1477. tkWString:
  1478. begin
  1479. case (PropInfo^.PropProcs shr 2) and 3 of
  1480. ptField:
  1481. PWideString(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1482. ptStatic,
  1483. ptVirtual:
  1484. begin
  1485. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1486. AMethod.Code:=PropInfo^.SetProc
  1487. else
  1488. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1489. AMethod.Data:=Instance;
  1490. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1491. TSetWideStrProcIndex(AMethod)(PropInfo^.Index,Value)
  1492. else
  1493. TSetWideStrProc(AMethod)(Value);
  1494. end;
  1495. end;
  1496. end;
  1497. end;
  1498. end;
  1499. Function GetUnicodeStrProp(Instance: TObject; const PropName: string): UnicodeString;
  1500. begin
  1501. Result:=GetUnicodeStrProp(Instance, FindPropInfo(Instance, PropName));
  1502. end;
  1503. procedure SetUnicodeStrProp(Instance: TObject; const PropName: string; const Value: UnicodeString);
  1504. begin
  1505. SetUnicodeStrProp(Instance,FindPropInfo(Instance,PropName),Value);
  1506. end;
  1507. Function GetUnicodeStrProp(Instance: TObject; PropInfo: PPropInfo): UnicodeString;
  1508. type
  1509. TGetUnicodeStrProcIndex=function(index:longint):UnicodeString of object;
  1510. TGetUnicodeStrProc=function():UnicodeString of object;
  1511. var
  1512. AMethod : TMethod;
  1513. begin
  1514. Result:='';
  1515. case Propinfo^.PropType^.Kind of
  1516. tkSString,tkAString:
  1517. Result:=UnicodeString(GetStrProp(Instance,PropInfo));
  1518. tkWString:
  1519. Result:=GetWideStrProp(Instance,PropInfo);
  1520. tkUString:
  1521. begin
  1522. case (PropInfo^.PropProcs) and 3 of
  1523. ptField:
  1524. Result := PUnicodeString(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  1525. ptStatic,
  1526. ptVirtual:
  1527. begin
  1528. if (PropInfo^.PropProcs and 3)=ptStatic then
  1529. AMethod.Code:=PropInfo^.GetProc
  1530. else
  1531. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;
  1532. AMethod.Data:=Instance;
  1533. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1534. Result:=TGetUnicodeStrProcIndex(AMethod)(PropInfo^.Index)
  1535. else
  1536. Result:=TGetUnicodeStrProc(AMethod)();
  1537. end;
  1538. end;
  1539. end;
  1540. end;
  1541. end;
  1542. Procedure SetUnicodeStrProp(Instance: TObject; PropInfo: PPropInfo; const Value: UnicodeString);
  1543. type
  1544. TSetUnicodeStrProcIndex=procedure(index:longint;s:UnicodeString) of object;
  1545. TSetUnicodeStrProc=procedure(s:UnicodeString) of object;
  1546. var
  1547. AMethod : TMethod;
  1548. begin
  1549. case Propinfo^.PropType^.Kind of
  1550. tkSString,tkAString:
  1551. SetStrProp(Instance,PropInfo,AnsiString(Value));
  1552. tkWString:
  1553. SetWideStrProp(Instance,PropInfo,Value);
  1554. tkUString:
  1555. begin
  1556. case (PropInfo^.PropProcs shr 2) and 3 of
  1557. ptField:
  1558. PUnicodeString(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1559. ptStatic,
  1560. ptVirtual:
  1561. begin
  1562. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1563. AMethod.Code:=PropInfo^.SetProc
  1564. else
  1565. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1566. AMethod.Data:=Instance;
  1567. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1568. TSetUnicodeStrProcIndex(AMethod)(PropInfo^.Index,Value)
  1569. else
  1570. TSetUnicodeStrProc(AMethod)(Value);
  1571. end;
  1572. end;
  1573. end;
  1574. end;
  1575. end;
  1576. {$ifndef FPUNONE}
  1577. { ---------------------------------------------------------------------
  1578. Float properties
  1579. ---------------------------------------------------------------------}
  1580. function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  1581. type
  1582. TGetExtendedProc = function:Extended of object;
  1583. TGetExtendedProcIndex = function(Index: integer): Extended of object;
  1584. TGetDoubleProc = function:Double of object;
  1585. TGetDoubleProcIndex = function(Index: integer): Double of object;
  1586. TGetSingleProc = function:Single of object;
  1587. TGetSingleProcIndex = function(Index: integer):Single of object;
  1588. TGetCurrencyProc = function : Currency of object;
  1589. TGetCurrencyProcIndex = function(Index: integer) : Currency of object;
  1590. var
  1591. AMethod : TMethod;
  1592. begin
  1593. Result:=0.0;
  1594. case PropInfo^.PropProcs and 3 of
  1595. ptField:
  1596. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  1597. ftSingle:
  1598. Result:=PSingle(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  1599. ftDouble:
  1600. Result:=PDouble(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  1601. ftExtended:
  1602. Result:=PExtended(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  1603. ftcomp:
  1604. Result:=PComp(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  1605. ftcurr:
  1606. Result:=PCurrency(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^;
  1607. end;
  1608. ptStatic,
  1609. ptVirtual:
  1610. begin
  1611. if (PropInfo^.PropProcs and 3)=ptStatic then
  1612. AMethod.Code:=PropInfo^.GetProc
  1613. else
  1614. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;
  1615. AMethod.Data:=Instance;
  1616. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  1617. ftSingle:
  1618. if ((PropInfo^.PropProcs shr 6) and 1)=0 then
  1619. Result:=TGetSingleProc(AMethod)()
  1620. else
  1621. Result:=TGetSingleProcIndex(AMethod)(PropInfo^.Index);
  1622. ftDouble:
  1623. if ((PropInfo^.PropProcs shr 6) and 1)=0 then
  1624. Result:=TGetDoubleProc(AMethod)()
  1625. else
  1626. Result:=TGetDoubleProcIndex(AMethod)(PropInfo^.Index);
  1627. ftExtended:
  1628. if ((PropInfo^.PropProcs shr 6) and 1)=0 then
  1629. Result:=TGetExtendedProc(AMethod)()
  1630. else
  1631. Result:=TGetExtendedProcIndex(AMethod)(PropInfo^.Index);
  1632. ftCurr:
  1633. if ((PropInfo^.PropProcs shr 6) and 1)=0 then
  1634. Result:=TGetCurrencyProc(AMethod)()
  1635. else
  1636. Result:=TGetCurrencyProcIndex(AMethod)(PropInfo^.Index);
  1637. end;
  1638. end;
  1639. end;
  1640. end;
  1641. Procedure SetFloatProp(Instance : TObject;PropInfo : PPropInfo; Value : Extended);
  1642. type
  1643. TSetExtendedProc = procedure(const AValue: Extended) of object;
  1644. TSetExtendedProcIndex = procedure(Index: integer; AValue: Extended) of object;
  1645. TSetDoubleProc = procedure(const AValue: Double) of object;
  1646. TSetDoubleProcIndex = procedure(Index: integer; AValue: Double) of object;
  1647. TSetSingleProc = procedure(const AValue: Single) of object;
  1648. TSetSingleProcIndex = procedure(Index: integer; AValue: Single) of object;
  1649. TSetCurrencyProc = procedure(const AValue: Currency) of object;
  1650. TSetCurrencyProcIndex = procedure(Index: integer; AValue: Currency) of object;
  1651. Var
  1652. AMethod : TMethod;
  1653. begin
  1654. case (PropInfo^.PropProcs shr 2) and 3 of
  1655. ptfield:
  1656. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  1657. ftSingle:
  1658. PSingle(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1659. ftDouble:
  1660. PDouble(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1661. ftExtended:
  1662. PExtended(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1663. {$ifdef FPC_COMP_IS_INT64}
  1664. ftComp:
  1665. PComp(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=trunc(Value);
  1666. {$else FPC_COMP_IS_INT64}
  1667. ftComp:
  1668. PComp(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Comp(Value);
  1669. {$endif FPC_COMP_IS_INT64}
  1670. ftCurr:
  1671. PCurrency(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  1672. end;
  1673. ptStatic,
  1674. ptVirtual:
  1675. begin
  1676. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1677. AMethod.Code:=PropInfo^.SetProc
  1678. else
  1679. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1680. AMethod.Data:=Instance;
  1681. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  1682. ftSingle:
  1683. if ((PropInfo^.PropProcs shr 6) and 1)=0 then
  1684. TSetSingleProc(AMethod)(Value)
  1685. else
  1686. TSetSingleProcIndex(AMethod)(PropInfo^.Index,Value);
  1687. ftDouble:
  1688. if ((PropInfo^.PropProcs shr 6) and 1)=0 then
  1689. TSetDoubleProc(AMethod)(Value)
  1690. else
  1691. TSetDoubleProcIndex(AMethod)(PropInfo^.Index,Value);
  1692. ftExtended:
  1693. if ((PropInfo^.PropProcs shr 6) and 1)=0 then
  1694. TSetExtendedProc(AMethod)(Value)
  1695. else
  1696. TSetExtendedProcIndex(AMethod)(PropInfo^.Index,Value);
  1697. ftCurr:
  1698. if ((PropInfo^.PropProcs shr 6) and 1)=0 then
  1699. TSetCurrencyProc(AMethod)(Value)
  1700. else
  1701. TSetCurrencyProcIndex(AMethod)(PropInfo^.Index,Value);
  1702. end;
  1703. end;
  1704. end;
  1705. end;
  1706. function GetFloatProp(Instance: TObject; const PropName: string): Extended;
  1707. begin
  1708. Result:=GetFloatProp(Instance,FindPropInfo(Instance,PropName))
  1709. end;
  1710. Procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Extended);
  1711. begin
  1712. SetFloatProp(Instance,FindPropInfo(Instance,PropName),Value);
  1713. end;
  1714. {$endif}
  1715. { ---------------------------------------------------------------------
  1716. Method properties
  1717. ---------------------------------------------------------------------}
  1718. Function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  1719. type
  1720. TGetMethodProcIndex=function(Index: Longint): TMethod of object;
  1721. TGetMethodProc=function(): TMethod of object;
  1722. var
  1723. value: PMethod;
  1724. AMethod : TMethod;
  1725. begin
  1726. Result.Code:=nil;
  1727. Result.Data:=nil;
  1728. case (PropInfo^.PropProcs) and 3 of
  1729. ptField:
  1730. begin
  1731. Value:=PMethod(Pointer(Instance)+PtrUInt(PropInfo^.GetProc));
  1732. if Value<>nil then
  1733. Result:=Value^;
  1734. end;
  1735. ptStatic,
  1736. ptVirtual:
  1737. begin
  1738. if (PropInfo^.PropProcs and 3)=ptStatic then
  1739. AMethod.Code:=PropInfo^.GetProc
  1740. else
  1741. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;
  1742. AMethod.Data:=Instance;
  1743. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1744. Result:=TGetMethodProcIndex(AMethod)(PropInfo^.Index)
  1745. else
  1746. Result:=TGetMethodProc(AMethod)();
  1747. end;
  1748. end;
  1749. end;
  1750. Procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo; const Value : TMethod);
  1751. type
  1752. TSetMethodProcIndex=procedure(index:longint;p:TMethod) of object;
  1753. TSetMethodProc=procedure(p:TMethod) of object;
  1754. var
  1755. AMethod : TMethod;
  1756. begin
  1757. case (PropInfo^.PropProcs shr 2) and 3 of
  1758. ptField:
  1759. PMethod(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^ := Value;
  1760. ptStatic,
  1761. ptVirtual:
  1762. begin
  1763. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  1764. AMethod.Code:=PropInfo^.SetProc
  1765. else
  1766. AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  1767. AMethod.Data:=Instance;
  1768. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  1769. TSetMethodProcIndex(AMethod)(PropInfo^.Index,Value)
  1770. else
  1771. TSetMethodProc(AMethod)(Value);
  1772. end;
  1773. end;
  1774. end;
  1775. Function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
  1776. begin
  1777. Result:=GetMethodProp(Instance,FindPropInfo(Instance,PropName));
  1778. end;
  1779. Procedure SetMethodProp(Instance: TObject; const PropName: string; const Value: TMethod);
  1780. begin
  1781. SetMethodProp(Instance,FindPropInfo(Instance,PropName),Value);
  1782. end;
  1783. { ---------------------------------------------------------------------
  1784. Variant properties
  1785. ---------------------------------------------------------------------}
  1786. Procedure CheckVariantEvent(P : CodePointer);
  1787. begin
  1788. If (P=Nil) then
  1789. Raise Exception.Create(SErrNoVariantSupport);
  1790. end;
  1791. Function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
  1792. begin
  1793. CheckVariantEvent(CodePointer(OnGetVariantProp));
  1794. Result:=OnGetVariantProp(Instance,PropInfo);
  1795. end;
  1796. Procedure SetVariantProp(Instance : TObject;PropInfo : PPropInfo; const Value: Variant);
  1797. begin
  1798. CheckVariantEvent(CodePointer(OnSetVariantProp));
  1799. OnSetVariantProp(Instance,PropInfo,Value);
  1800. end;
  1801. Function GetVariantProp(Instance: TObject; const PropName: string): Variant;
  1802. begin
  1803. Result:=GetVariantProp(Instance,FindPropInfo(Instance,PropName));
  1804. end;
  1805. Procedure SetVariantProp(Instance: TObject; const PropName: string; const Value: Variant);
  1806. begin
  1807. SetVariantprop(instance,FindpropInfo(Instance,PropName),Value);
  1808. end;
  1809. { ---------------------------------------------------------------------
  1810. All properties through variant.
  1811. ---------------------------------------------------------------------}
  1812. Function GetPropValue(Instance: TObject; const PropName: string): Variant;
  1813. begin
  1814. Result := GetPropValue(Instance,FindPropInfo(Instance, PropName));
  1815. end;
  1816. Function GetPropValue(Instance: TObject; const PropName: string; PreferStrings: Boolean): Variant;
  1817. begin
  1818. Result := GetPropValue(Instance,FindPropInfo(Instance, PropName),PreferStrings);
  1819. end;
  1820. Function GetPropValue(Instance: TObject; PropInfo: PPropInfo): Variant;
  1821. begin
  1822. Result := GetPropValue(Instance, PropInfo, True);
  1823. end;
  1824. Function GetPropValue(Instance: TObject; PropInfo: PPropInfo; PreferStrings: Boolean): Variant;
  1825. begin
  1826. CheckVariantEvent(CodePointer(OnGetPropValue));
  1827. Result:=OnGetPropValue(Instance,PropInfo,PreferStrings);
  1828. end;
  1829. Procedure SetPropValue(Instance: TObject; const PropName: string; const Value: Variant);
  1830. begin
  1831. SetPropValue(Instance, FindPropInfo(Instance, PropName), Value);
  1832. end;
  1833. Procedure SetPropValue(Instance: TObject; PropInfo: PPropInfo; const Value: Variant);
  1834. begin
  1835. CheckVariantEvent(CodePointer(OnSetPropValue));
  1836. OnSetPropValue(Instance,PropInfo,Value);
  1837. end;
  1838. { ---------------------------------------------------------------------
  1839. Easy access methods that appeared in Delphi 5
  1840. ---------------------------------------------------------------------}
  1841. Function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
  1842. begin
  1843. Result:=GetPropInfo(Instance,PropName)<>Nil;
  1844. end;
  1845. Function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;
  1846. begin
  1847. Result:=GetPropInfo(AClass,PropName)<>Nil;
  1848. end;
  1849. Function PropIsType(Instance: TObject; const PropName: string; TypeKind: TTypeKind): Boolean;
  1850. begin
  1851. Result:=PropType(Instance,PropName)=TypeKind
  1852. end;
  1853. Function PropIsType(AClass: TClass; const PropName: string; TypeKind: TTypeKind): Boolean;
  1854. begin
  1855. Result:=PropType(AClass,PropName)=TypeKind
  1856. end;
  1857. Function PropType(Instance: TObject; const PropName: string): TTypeKind;
  1858. begin
  1859. Result:=FindPropInfo(Instance,PropName)^.PropType^.Kind;
  1860. end;
  1861. Function PropType(AClass: TClass; const PropName: string): TTypeKind;
  1862. begin
  1863. Result:=FindPropInfo(AClass,PropName)^.PropType^.Kind;
  1864. end;
  1865. Function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
  1866. begin
  1867. Result:=IsStoredProp(instance,FindPropInfo(Instance,PropName));
  1868. end;
  1869. { TProcedureParam }
  1870. function TProcedureParam.GetParamType: PTypeInfo;
  1871. begin
  1872. Result := DerefTypeInfoPtr(ParamTypeRef);
  1873. end;
  1874. { TManagedField }
  1875. function TManagedField.GetTypeRef: PTypeInfo;
  1876. begin
  1877. Result := DerefTypeInfoPtr(TypeRefRef);
  1878. end;
  1879. { TArrayTypeData }
  1880. function TArrayTypeData.GetElType: PTypeInfo;
  1881. begin
  1882. Result := DerefTypeInfoPtr(ElTypeRef);
  1883. end;
  1884. function TArrayTypeData.GetDims(aIndex: Byte): PTypeInfo;
  1885. begin
  1886. Result := DerefTypeInfoPtr(DimsRef[aIndex]);
  1887. end;
  1888. { TProcedureSignature }
  1889. function TProcedureSignature.GetResultType: PTypeInfo;
  1890. begin
  1891. Result := DerefTypeInfoPtr(ResultTypeRef);
  1892. end;
  1893. function TProcedureSignature.GetParam(ParamIndex: Integer): PProcedureParam;
  1894. begin
  1895. if (ParamIndex<0)or(ParamIndex>=ParamCount) then
  1896. Exit(nil);
  1897. Result := PProcedureParam(PByte(@Flags) + SizeOf(Self));
  1898. while ParamIndex > 0 do
  1899. begin
  1900. Result := PProcedureParam(aligntoptr((PByte(@Result^.Name) + (Length(Result^.Name) + 1) * SizeOf(AnsiChar))));
  1901. dec(ParamIndex);
  1902. end;
  1903. end;
  1904. { TTypeData }
  1905. function TTypeData.GetBaseType: PTypeInfo;
  1906. begin
  1907. Result := DerefTypeInfoPtr(BaseTypeRef);
  1908. end;
  1909. function TTypeData.GetCompType: PTypeInfo;
  1910. begin
  1911. Result := DerefTypeInfoPtr(CompTypeRef);
  1912. end;
  1913. function TTypeData.GetParentInfo: PTypeInfo;
  1914. begin
  1915. Result := DerefTypeInfoPtr(ParentInfoRef);
  1916. end;
  1917. function TTypeData.GetHelperParent: PTypeInfo;
  1918. begin
  1919. Result := DerefTypeInfoPtr(HelperParentRef);
  1920. end;
  1921. function TTypeData.GetExtendedInfo: PTypeInfo;
  1922. begin
  1923. Result := DerefTypeInfoPtr(ExtendedInfoRef);
  1924. end;
  1925. function TTypeData.GetIntfParent: PTypeInfo;
  1926. begin
  1927. Result := DerefTypeInfoPtr(IntfParentRef);
  1928. end;
  1929. function TTypeData.GetRawIntfParent: PTypeInfo;
  1930. begin
  1931. Result := DerefTypeInfoPtr(RawIntfParentRef);
  1932. end;
  1933. function TTypeData.GetElType: PTypeInfo;
  1934. begin
  1935. Result := DerefTypeInfoPtr(elTypeRef);
  1936. end;
  1937. function TTypeData.GetElType2: PTypeInfo;
  1938. begin
  1939. Result := DerefTypeInfoPtr(elType2Ref);
  1940. end;
  1941. function TTypeData.GetInstanceType: PTypeInfo;
  1942. begin
  1943. Result := DerefTypeInfoPtr(InstanceTypeRef);
  1944. end;
  1945. function TTypeData.GetRefType: PTypeInfo;
  1946. begin
  1947. Result := DerefTypeInfoPtr(RefTypeRef);
  1948. end;
  1949. { TPropInfo }
  1950. function TPropInfo.GetPropType: PTypeInfo;
  1951. begin
  1952. Result := DerefTypeInfoPtr(PropTypeRef);
  1953. end;
  1954. end.