typinfo.pp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl
  5. member of the Free Pascal development team
  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. { This unit provides the same Functionality as the TypInfo Unit }
  13. { of Delphi }
  14. unit typinfo;
  15. interface
  16. {$MODE objfpc}
  17. uses SysUtils;
  18. // temporary types:
  19. type
  20. //{$ifndef HASVARIANT}
  21. Variant = Pointer;
  22. //{$endif}
  23. {$MINENUMSIZE 1 this saves a lot of memory }
  24. // if you change one of the following enumeration types
  25. // you have also to change the compiler in an appropriate way !
  26. TTypeKind = (tkUnknown,tkInteger,tkChar,tkEnumeration,
  27. tkFloat,tkSet,tkMethod,tkSString,tkLString,tkAString,
  28. tkWString,tkVariant,tkArray,tkRecord,tkInterface,
  29. tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord,
  30. tkDynArray,tkInterfaceRaw);
  31. TTOrdType = (otSByte,otUByte,otSWord,otUWord,otSLong,otULong);
  32. TFloatType = (ftSingle,ftDouble,ftExtended,ftComp,ftCurr);
  33. TMethodKind = (mkProcedure,mkFunction,mkConstructor,mkDestructor,
  34. mkClassProcedure, mkClassFunction);
  35. TParamFlags = set of (pfVar,pfConst,pfArray,pfAddress,pfReference,pfOut);
  36. TIntfFlags = set of (ifHasGuid,ifDispInterface,ifDispatch);
  37. {$MINENUMSIZE DEFAULT}
  38. const
  39. ptField = 0;
  40. ptStatic = 1;
  41. ptVirtual = 2;
  42. ptConst = 3;
  43. tkString = tkSString;
  44. type
  45. TTypeKinds = set of TTypeKind;
  46. {$PACKRECORDS 1}
  47. TTypeInfo = record
  48. Kind : TTypeKind;
  49. Name : ShortString;
  50. // here the type data follows as TTypeData record
  51. end;
  52. PTypeInfo = ^TTypeInfo;
  53. PPTypeInfo = ^PTypeInfo;
  54. PTypeData = ^TTypeData;
  55. TTypeData = packed record
  56. case TTypeKind of
  57. tkUnKnown,tkLString,tkWString,tkAString,tkVariant:
  58. ();
  59. tkInteger,tkChar,tkEnumeration,tkWChar:
  60. (OrdType : TTOrdType;
  61. case TTypeKind of
  62. tkInteger,tkChar,tkEnumeration,tkBool,tkWChar : (
  63. MinValue,MaxValue : Longint;
  64. case TTypeKind of
  65. tkEnumeration:
  66. (
  67. BaseType : PTypeInfo;
  68. NameList : ShortString)
  69. );
  70. tkSet:
  71. (CompType : PTypeInfo)
  72. );
  73. tkFloat:
  74. (FloatType : TFloatType);
  75. tkSString:
  76. (MaxLength : Byte);
  77. tkClass:
  78. (ClassType : TClass;
  79. ParentInfo : PTypeInfo;
  80. PropCount : SmallInt;
  81. UnitName : ShortString
  82. // here the properties follow as array of TPropInfo
  83. );
  84. tkMethod:
  85. (MethodKind : TMethodKind;
  86. ParamCount : Byte;
  87. ParamList : array[0..1023] of Char
  88. {in reality ParamList is a array[1..ParamCount] of:
  89. record
  90. Flags : TParamFlags;
  91. ParamName : ShortString;
  92. TypeName : ShortString;
  93. end;
  94. followed by
  95. ResultType : ShortString}
  96. );
  97. tkInt64:
  98. (MinInt64Value, MaxInt64Value: Int64);
  99. tkQWord:
  100. (MinQWordValue, MaxQWordValue: QWord);
  101. tkInterface,
  102. tkInterfaceRaw:
  103. (
  104. IntfParent: PPTypeInfo;
  105. IID: PGUID;
  106. IIDStr: ShortString;
  107. IntfUnit: ShortString;
  108. );
  109. end;
  110. // unsed, just for completeness
  111. TPropData = packed record
  112. PropCount : Word;
  113. PropList : record end;
  114. end;
  115. PPropInfo = ^TPropInfo;
  116. TPropInfo = packed record
  117. PropType : PTypeInfo;
  118. GetProc : Pointer;
  119. SetProc : Pointer;
  120. StoredProc : Pointer;
  121. Index : Integer;
  122. Default : Longint;
  123. NameIndex : SmallInt;
  124. // contains the type of the Get/Set/Storedproc, see also ptxxx
  125. // bit 0..1 GetProc
  126. // 2..3 SetProc
  127. // 4..5 StoredProc
  128. // 6 : true, constant index property
  129. PropProcs : Byte;
  130. Name : ShortString;
  131. end;
  132. TProcInfoProc = Procedure(PropInfo : PPropInfo) of object;
  133. PPropList = ^TPropList;
  134. TPropList = array[0..65535] of PPropInfo;
  135. const
  136. tkAny = [Low(TTypeKind)..High(TTypeKind)];
  137. tkMethods = [tkMethod];
  138. tkProperties = tkAny-tkMethods-[tkUnknown];
  139. // general property handling
  140. Function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
  141. Function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string) : PPropInfo;
  142. Function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string; AKinds : TTypeKinds) : PPropInfo;
  143. Function GetPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  144. Function GetPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  145. Function GetPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  146. Function GetPropInfo(AClass: TClass; const PropName: string): PPropInfo;
  147. Function FindPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  148. Function FindPropInfo(AClass:TClass;const PropName: string): PPropInfo;
  149. Procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
  150. Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds; PropList : PPropList) : Integer;
  151. // Property information routines.
  152. Function IsStoredProp(Instance: TObject;PropInfo : PPropInfo) : Boolean;
  153. Function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
  154. Function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
  155. Function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;
  156. Function PropType(Instance: TObject; const PropName: string): TTypeKind;
  157. Function PropType(AClass: TClass; const PropName: string): TTypeKind;
  158. Function PropIsType(Instance: TObject; const PropName: string; TypeKind: TTypeKind): Boolean;
  159. Function PropIsType(AClass: TClass; const PropName: string; TypeKind: TTypeKind): Boolean;
  160. // subroutines to read/write properties
  161. Function GetOrdProp(Instance: TObject; PropInfo : PPropInfo) : Longint;
  162. Function GetOrdProp(Instance: TObject; const PropName: string): Longint;
  163. Procedure SetOrdProp(Instance: TObject; PropInfo : PPropInfo; Value : Longint);
  164. Procedure SetOrdProp(Instance: TObject; const PropName: string; Value: Longint);
  165. Function GetEnumProp(Instance: TObject; const PropName: string): string;
  166. Function GetEnumProp(Instance: TObject; const PropInfo: PPropInfo): string;
  167. Procedure SetEnumProp(Instance: TObject; const PropName: string;const Value: string);
  168. Procedure SetEnumProp(Instance: TObject; const PropInfo: PPropInfo;const Value: string);
  169. Function GetSetProp(Instance: TObject; const PropName: string): string;
  170. Function GetSetProp(Instance: TObject; const PropName: string; Brackets: Boolean): string;
  171. Function GetSetProp(Instance: TObject; const PropInfo: PPropInfo; Brackets: Boolean): string;
  172. Procedure SetSetProp(Instance: TObject; const PropName: string; const Value: string);
  173. Procedure SetSetProp(Instance: TObject; const PropInfo: PPropInfo; const Value: string);
  174. Function GetStrProp(Instance: TObject; PropInfo : PPropInfo) : Ansistring;
  175. Function GetStrProp(Instance: TObject; const PropName: string): string;
  176. Procedure SetStrProp(Instance: TObject; const PropName: string; const Value: AnsiString);
  177. Procedure SetStrProp(Instance: TObject; PropInfo : PPropInfo; const Value : Ansistring);
  178. Function GetFloatProp(Instance: TObject; PropInfo : PPropInfo) : Extended;
  179. Function GetFloatProp(Instance: TObject; const PropName: string): Extended;
  180. Procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Extended);
  181. Procedure SetFloatProp(Instance: TObject; PropInfo : PPropInfo; Value : Extended);
  182. Function GetVariantProp(Instance: TObject; PropInfo : PPropInfo): Variant;
  183. Function GetVariantProp(Instance: TObject; const PropName: string): Variant;
  184. Procedure SetVariantProp(Instance: TObject; const PropName: string; const Value: Variant);
  185. Procedure SetVariantProp(Instance: TObject; PropInfo : PPropInfo; const Value: Variant);
  186. Function GetObjectProp(Instance: TObject; const PropName: string): TObject;
  187. Function GetObjectProp(Instance: TObject; const PropName: string; MinClass: TClass): TObject;
  188. Function GetObjectProp(Instance: TObject; PropInfo: PPropInfo; MinClass: TClass): TObject;
  189. Procedure SetObjectProp(Instance: TObject; const PropName: string; Value: TObject);
  190. Procedure SetObjectProp(Instance: TObject; PropInfo: PPropInfo; Value: TObject);
  191. Function GetObjectPropClass(Instance: TObject; const PropName: string): TClass;
  192. Function GetMethodProp(Instance: TObject; PropInfo: PPropInfo) : TMethod;
  193. Function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
  194. Procedure SetMethodProp(Instance: TObject; PropInfo: PPropInfo; const Value : TMethod);
  195. Procedure SetMethodProp(Instance: TObject; const PropName: string; const Value: TMethod);
  196. Function GetInt64Prop(Instance: TObject; PropInfo: PPropInfo): Int64;
  197. Function GetInt64Prop(Instance: TObject; const PropName: string): Int64;
  198. Procedure SetInt64Prop(Instance: TObject; PropInfo: PPropInfo; const Value: Int64);
  199. Procedure SetInt64Prop(Instance: TObject; const PropName: string; const Value: Int64);
  200. Function GetPropValue(Instance: TObject; const PropName: string): Variant;
  201. Function GetPropValue(Instance: TObject; const PropName: string; PreferStrings: Boolean): Variant;
  202. Procedure SetPropValue(Instance: TObject; const PropName: string; const Value: Variant);
  203. // Auxiliary routines, which may be useful
  204. Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
  205. Function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
  206. function SetToString(PropInfo: PPropInfo; Value: Integer; Brackets: Boolean) : String;
  207. function SetToString(PropInfo: PPropInfo; Value: Integer) : String;
  208. function StringToSet(PropInfo: PPropInfo; const Value: string): Integer;
  209. const
  210. BooleanIdents: array[Boolean] of String = ('False', 'True');
  211. DotSep: String = '.';
  212. Type
  213. EPropertyError = Class(Exception);
  214. Implementation
  215. ResourceString
  216. SErrPropertyNotFound = 'Unknown property: "%s"';
  217. SErrUnknownEnumValue = 'Unknown enumeration value: "%s"';
  218. type
  219. PMethod = ^TMethod;
  220. { ---------------------------------------------------------------------
  221. Auxiliary methods
  222. ---------------------------------------------------------------------}
  223. Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
  224. Var PS : PShortString;
  225. PT : PTypeData;
  226. begin
  227. PT:=GetTypeData(TypeInfo);
  228. // ^.BaseType);
  229. // If PT^.MinValue<0 then Value:=Ord(Value<>0); {map to 0/1}
  230. PS:=@PT^.NameList;
  231. While Value>0 Do
  232. begin
  233. PS:=PShortString(pointer(PS)+PByte(PS)^+1);
  234. Dec(Value);
  235. end;
  236. Result:=PS^;
  237. end;
  238. Function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
  239. Var PS : PShortString;
  240. PT : PTypeData;
  241. Count : longint;
  242. begin
  243. If Length(Name)=0 then exit(-1);
  244. PT:=GetTypeData(TypeInfo);
  245. Count:=0;
  246. Result:=-1;
  247. PS:=@PT^.NameList;
  248. While (Result=-1) and (PByte(PS)^<>0) do
  249. begin
  250. If CompareText(PS^, Name) = 0 then
  251. Result:=Count;
  252. PS:=PShortString(pointer(PS)+PByte(PS)^+1);
  253. Inc(Count);
  254. end;
  255. end;
  256. Function SetToString(PropInfo: PPropInfo; Value: Integer; Brackets: Boolean) : String;
  257. Var
  258. I : Integer;
  259. PTI : PTypeInfo;
  260. begin
  261. PTI:=GetTypeData(PropInfo^.PropType)^.CompType;
  262. Result:='';
  263. For I:=0 to SizeOf(Integer)*8-1 do
  264. begin
  265. if ((Value and 1)<>0) then
  266. begin
  267. If Result='' then
  268. Result:=GetEnumName(PTI,i)
  269. else
  270. Result:=Result+','+GetEnumName(PTI,I);
  271. end;
  272. Value:=Value shr 1;
  273. end;
  274. if Brackets then
  275. Result:='['+Result+']';
  276. end;
  277. Function SetToString(PropInfo: PPropInfo; Value: Integer) : String;
  278. begin
  279. Result:=SetToString(PropInfo,Value,False);
  280. end;
  281. Const
  282. SetDelim = ['[',']',',',' '];
  283. Function GetNextElement(Var S : String) : String;
  284. Var
  285. J : Integer;
  286. begin
  287. J:=1;
  288. Result:='';
  289. If Length(S)>0 then
  290. begin
  291. While (J<=Length(S)) and Not (S[j] in SetDelim) do
  292. Inc(j);
  293. Result:=Copy(S,1,j-1);
  294. Delete(S,1,j);
  295. end;
  296. end;
  297. Function StringToSet(PropInfo: PPropInfo; const Value: string): Integer;
  298. Var
  299. S,T : String;
  300. I : Integer;
  301. PTI : PTypeInfo;
  302. begin
  303. Result:=0;
  304. PTI:=GetTypeData(PropInfo^.PropType)^.Comptype;
  305. S:=Value;
  306. I:=1;
  307. If Length(S)>0 then
  308. begin
  309. While (I<=Length(S)) and (S[i] in SetDelim) do
  310. Inc(I);
  311. Delete(S,1,i-1);
  312. end;
  313. While (S<>'') do
  314. begin
  315. T:=GetNextElement(S);
  316. if T<>'' then
  317. begin
  318. I:=GetEnumValue(PTI,T);
  319. if (I<0) then
  320. raise EPropertyError.CreateFmt(SErrUnknownEnumValue, [T]);
  321. Result:=Result or (1 shl i);
  322. end;
  323. end;
  324. end;
  325. Function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
  326. begin
  327. GetTypeData:=PTypeData(pointer(TypeInfo)+2+PByte(pointer(TypeInfo)+1)^);
  328. end;
  329. { ---------------------------------------------------------------------
  330. Low-level calling of methods.
  331. ---------------------------------------------------------------------}
  332. {$ASMMODE ATT}
  333. Function CallIntegerFunc(s: Pointer; Address: Pointer; Index, IValue: LongInt): Int64; assembler;
  334. asm
  335. movl S,%esi
  336. movl Address,%edi
  337. // ? Indexed Function
  338. movl Index,%eax
  339. testl %eax,%eax
  340. je .LINoPush
  341. movl IValue,%eax
  342. pushl %eax
  343. .LINoPush:
  344. push %esi
  345. call %edi
  346. // now the result is in EDX:EAX
  347. end;
  348. Function CallIntegerProc(s : Pointer;Address : Pointer;Value : Integer; INdex,IValue : Longint) : Integer;assembler;
  349. asm
  350. movl S,%esi
  351. movl Address,%edi
  352. // Push value to set
  353. movl Value,%eax
  354. pushl %eax
  355. // ? Indexed Procedure
  356. movl Index,%eax
  357. testl %eax,%eax
  358. je .LIPNoPush
  359. movl IValue,%eax
  360. pushl %eax
  361. .LIPNoPush:
  362. pushl %esi
  363. call %edi
  364. end;
  365. Function CallExtendedFunc(s : Pointer;Address : Pointer; INdex,IValue : Longint) : Extended;assembler;
  366. asm
  367. movl S,%esi
  368. movl Address,%edi
  369. // ? Indexed Function
  370. movl Index,%eax
  371. testl %eax,%eax
  372. je .LINoPush
  373. movl IValue,%eax
  374. pushl %eax
  375. .LINoPush:
  376. push %esi
  377. call %edi
  378. //
  379. end;
  380. Function CallExtendedProc(s : Pointer;Address : Pointer;Value : Extended; INdex,IVAlue : Longint) : Integer;assembler;
  381. asm
  382. movl S,%esi
  383. movl Address,%edi
  384. // Push value to set
  385. leal Value,%eax
  386. pushl (%eax)
  387. pushl 4(%eax)
  388. pushl 8(%eax)
  389. // ? Indexed Procedure
  390. movl Index,%eax
  391. testl %eax,%eax
  392. je .LIPNoPush
  393. movl IValue,%eax
  394. pushl %eax
  395. .LIPNoPush:
  396. push %esi
  397. call %edi
  398. end;
  399. Function CallBooleanFunc(s : Pointer;Address : Pointer; Index,IValue : Longint) : Boolean;assembler;
  400. asm
  401. movl S,%esi
  402. movl Address,%edi
  403. // ? Indexed Function
  404. movl Index,%eax
  405. testl %eax,%eax
  406. je .LBNoPush
  407. movl IValue,%eax
  408. pushl %eax
  409. .LBNoPush:
  410. push %esi
  411. call %edi
  412. end;
  413. // Assembler Functions can't have short stringreturn values.
  414. // So we make a Procedure with var parameter.
  415. // That's not true (FK)
  416. Procedure CallSStringFunc(s : Pointer;Address : Pointer; INdex,IValue : Longint;
  417. Var Res: Shortstring);assembler;
  418. asm
  419. movl S,%esi
  420. movl Address,%edi
  421. // ? Indexed Function
  422. movl Index,%eax
  423. testl %eax,%eax
  424. jnz .LSSNoPush
  425. movl IValue,%eax
  426. pushl %eax
  427. // the result is stored in an invisible parameter
  428. pushl Res
  429. .LSSNoPush:
  430. push %esi
  431. call %edi
  432. end;
  433. Procedure CallSStringProc(s : Pointer;Address : Pointer;Const Value : ShortString; INdex,IVAlue : Longint);assembler;
  434. asm
  435. movl S,%esi
  436. movl Address,%edi
  437. // Push value to set
  438. movl Value,%eax
  439. pushl %eax
  440. // ? Indexed Procedure
  441. movl Index,%eax
  442. testl %eax,%eax
  443. je .LSSPNoPush
  444. movl IValue,%eax
  445. pushl %eax
  446. .LSSPNoPush:
  447. pushl %esi
  448. call %edi
  449. end;
  450. { ---------------------------------------------------------------------
  451. Basic Type information functions.
  452. ---------------------------------------------------------------------}
  453. Function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string) : PPropInfo;
  454. var
  455. hp : PTypeData;
  456. i : longint;
  457. p : string;
  458. begin
  459. P:=UpCase(PropName);
  460. while Assigned(TypeInfo) do
  461. begin
  462. // skip the name
  463. hp:=GetTypeData(Typeinfo);
  464. // the class info rtti the property rtti follows immediatly
  465. Result:=PPropInfo(pointer(@hp^.UnitName)+Length(hp^.UnitName)+1+SizeOF(Word));
  466. for i:=1 to hp^.PropCount do
  467. begin
  468. // found a property of that name ?
  469. if Upcase(Result^.Name)=P then
  470. exit;
  471. // skip to next property
  472. Result:=PPropInfo(pointer(@Result^.Name)+byte(Result^.Name[0])+1);
  473. end;
  474. // parent class
  475. Typeinfo:=hp^.ParentInfo;
  476. end;
  477. Result:=Nil;
  478. end;
  479. Function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string; Akinds : TTypeKinds) : PPropInfo;
  480. begin
  481. Result:=GetPropInfo(TypeInfo,PropName);
  482. If (Akinds<>[]) then
  483. If (Result<>Nil) then
  484. If Not (Result^.PropType^.Kind in AKinds) then
  485. Result:=Nil;
  486. end;
  487. Function GetPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  488. begin
  489. Result:=GetPropInfo(PTypeInfo(AClass.ClassInfo),PropName,AKinds);
  490. end;
  491. Function GetPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  492. begin
  493. Result:=GetPropInfo(Instance.ClassType,PropName,AKinds);
  494. end;
  495. Function GetPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  496. begin
  497. Result:=GetPropInfo(Instance,PropName,[]);
  498. end;
  499. Function GetPropInfo(AClass: TClass; const PropName: string): PPropInfo;
  500. begin
  501. Result:=GetPropInfo(AClass,PropName,[]);
  502. end;
  503. Function FindPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  504. begin
  505. result:=GetPropInfo(Instance, PropName);
  506. if Result=nil then
  507. Raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
  508. end;
  509. Function FindPropInfo(AClass:TClass;const PropName: string): PPropInfo;
  510. begin
  511. result:=GetPropInfo(AClass,PropName);
  512. if result=nil then
  513. Raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
  514. end;
  515. Function IsStoredProp(Instance : TObject;PropInfo : PPropInfo) : Boolean;
  516. begin
  517. case (PropInfo^.PropProcs shr 4) and 3 of
  518. ptfield:
  519. IsStoredProp:=PBoolean(Pointer(Instance)+Longint(PropInfo^.StoredProc))^;
  520. ptstatic:
  521. IsStoredProp:=CallBooleanFunc(Instance,PropInfo^.StoredProc,0,0);
  522. ptvirtual:
  523. IsStoredProp:=CallBooleanFunc(Instance,ppointer(Pointer(Instance.ClassType)+Longint(PropInfo^.StoredProc))^,0,0);
  524. ptconst:
  525. IsStoredProp:=LongBool(PropInfo^.StoredProc);
  526. end;
  527. end;
  528. Procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
  529. {
  530. Store Pointers to property information in the list pointed
  531. to by proplist. PRopList must contain enough space to hold ALL
  532. properties.
  533. }
  534. Type PWord = ^Word;
  535. Var TD : PTypeData;
  536. TP : PPropInfo;
  537. Count : Longint;
  538. begin
  539. TD:=GetTypeData(TypeInfo);
  540. // Get this objects TOTAL published properties count
  541. TP:=(@TD^.UnitName+Length(TD^.UnitName)+1);
  542. Count:=PWord(TP)^;
  543. // Now point TP to first propinfo record.
  544. Inc(Longint(TP),SizeOF(Word));
  545. While Count>0 do
  546. begin
  547. PropList^[0]:=TP;
  548. Inc(Longint(PropList),SizeOf(Pointer));
  549. // Point to TP next propinfo record.
  550. // Located at Name[Length(Name)+1] !
  551. TP:=PPropInfo(pointer(@TP^.Name)+PByte(@TP^.Name)^+1);
  552. Dec(Count);
  553. end;
  554. // recursive call for parent info.
  555. If TD^.Parentinfo<>Nil then
  556. GetPropInfos (TD^.ParentInfo,PropList);
  557. end;
  558. Procedure InsertProp (PL : PProplist;PI : PPropInfo; Count : longint);
  559. Var I : Longint;
  560. begin
  561. I:=0;
  562. While (I<Count) and (PI^.Name>PL^[I]^.Name) do Inc(I);
  563. If I<Count then
  564. Move(PL^[I], PL^[I+1], (Count - I) * SizeOf(Pointer));
  565. PL^[I]:=PI;
  566. end;
  567. Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds;
  568. PropList : PPropList) : Integer;
  569. {
  570. Store Pointers to property information OF A CERTAIN KIND in the list pointed
  571. to by proplist. PRopList must contain enough space to hold ALL
  572. properties.
  573. }
  574. Var TempList : PPropList;
  575. PropInfo : PPropinfo;
  576. I,Count : longint;
  577. begin
  578. Result:=0;
  579. Count:=GetTypeData(TypeInfo)^.Propcount;
  580. If Count>0 then
  581. begin
  582. GetMem(TempList,Count*SizeOf(Pointer));
  583. Try
  584. GetPropInfos(TypeInfo,TempList);
  585. For I:=0 to Count-1 do
  586. begin
  587. PropInfo:=TempList^[i];
  588. If PropInfo^.PropType^.Kind in TypeKinds then
  589. begin
  590. InsertProp(PropList,PropInfo,Result);
  591. Inc(Result);
  592. end;
  593. end;
  594. finally
  595. FreeMem(TempList,Count*SizeOf(Pointer));
  596. end;
  597. end;
  598. end;
  599. Procedure SetIndexValues (P: PPRopInfo; Var Index,IValue : Longint);
  600. begin
  601. Index:=((P^.PropProcs shr 6) and 1);
  602. If Index<>0 then
  603. IValue:=P^.Index
  604. else
  605. IValue:=0;
  606. end;
  607. { ---------------------------------------------------------------------
  608. Property access functions
  609. ---------------------------------------------------------------------}
  610. { ---------------------------------------------------------------------
  611. Ordinal properties
  612. ---------------------------------------------------------------------}
  613. Function GetOrdProp(Instance : TObject;PropInfo : PPropInfo) : Longint;
  614. var
  615. value,Index,Ivalue : longint;
  616. TypeInfo: PTypeInfo;
  617. begin
  618. SetIndexValues(PropInfo,Index,Ivalue);
  619. case (PropInfo^.PropProcs) and 3 of
  620. ptfield:
  621. Value:=PLongint(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  622. ptstatic:
  623. Value:=CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue);
  624. ptvirtual:
  625. Value:=CallIntegerFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue);
  626. end;
  627. { cut off unnecessary stuff }
  628. TypeInfo := PropInfo^.PropType;
  629. case TypeInfo^.Kind of
  630. tkChar, tkBool:
  631. Value:=Value and $ff;
  632. tkWChar:
  633. Value:=Value and $ffff;
  634. tkInteger:
  635. case GetTypeData(TypeInfo)^.OrdType of
  636. otSWord,otUWord:
  637. Value:=Value and $ffff;
  638. otSByte,otUByte:
  639. Value:=Value and $ff;
  640. end;
  641. end;
  642. GetOrdProp:=Value;
  643. end;
  644. Procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;
  645. Value : Longint);
  646. var
  647. Index,IValue : Longint;
  648. DataSize: Integer;
  649. begin
  650. if PropInfo^.PropType^.Kind <> tkClass then
  651. { cut off unnecessary stuff }
  652. case GetTypeData(PropInfo^.PropType)^.OrdType of
  653. otSWord,otUWord:
  654. begin
  655. Value:=Value and $ffff;
  656. DataSize := 2;
  657. end;
  658. otSByte,otUByte:
  659. begin
  660. Value:=Value and $ff;
  661. DataSize := 1;
  662. end;
  663. else
  664. DataSize := 4;
  665. end
  666. else
  667. DataSize := 4;
  668. SetIndexValues(PropInfo,Index,Ivalue);
  669. case (PropInfo^.PropProcs shr 2) and 3 of
  670. ptfield:
  671. case DataSize of
  672. 1: PByte(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Byte(Value);
  673. 2: PWord(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Word(Value);
  674. 4: PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  675. end;
  676. ptstatic:
  677. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  678. ptvirtual:
  679. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  680. end;
  681. end;
  682. Function GetOrdProp(Instance: TObject; const PropName: string): Longint;
  683. begin
  684. Result:=GetOrdProp(Instance,FindPropInfo(Instance,PropName));
  685. end;
  686. Procedure SetOrdProp(Instance: TObject; const PropName: string; Value: Longint);
  687. begin
  688. SetOrdProp(Instance,FindPropInfo(Instance,PropName),Value);
  689. end;
  690. Function GetEnumProp(Instance: TObject; Const PropInfo: PPropInfo): string;
  691. begin
  692. Result:=GetEnumName(PropInfo^.PropType, GetOrdProp(Instance, PropInfo));
  693. end;
  694. Function GetEnumProp(Instance: TObject; const PropName: string): string;
  695. begin
  696. Result:=GetEnumProp(Instance,FindPropInfo(Instance,PropName));
  697. end;
  698. Procedure SetEnumProp(Instance: TObject; const PropName: string; const Value: string);
  699. begin
  700. SetEnumProp(Instance,FindPropInfo(Instance,PropName),Value);
  701. end;
  702. Procedure SetEnumProp(Instance: TObject; Const PropInfo : PPropInfo; const Value: string);
  703. Var
  704. PV : Longint;
  705. begin
  706. If PropInfo<>Nil then
  707. begin
  708. PV:=GetEnumValue(PropInfo^.PropType, Value);
  709. if (PV<0) then
  710. raise EPropertyError.CreateFmt(SErrUnknownEnumValue, [Value]);
  711. SetOrdProp(Instance, PropInfo,PV);
  712. end;
  713. end;
  714. { ---------------------------------------------------------------------
  715. Set properties
  716. ---------------------------------------------------------------------}
  717. Function GetSetProp(Instance: TObject; const PropName: string): string;
  718. begin
  719. Result:=GetSetProp(Instance,PropName,False);
  720. end;
  721. Function GetSetProp(Instance: TObject; const PropName: string; Brackets: Boolean): string;
  722. begin
  723. Result:=GetSetProp(Instance,FindPropInfo(Instance,PropName),Brackets);
  724. end;
  725. Function GetSetProp(Instance: TObject; const PropInfo: PPropInfo; Brackets: Boolean): string;
  726. begin
  727. Result:=SetToString(PropInfo,GetOrdProp(Instance,PropInfo),Brackets);
  728. end;
  729. Procedure SetSetProp(Instance: TObject; const PropName: string; const Value: string);
  730. begin
  731. SetSetProp(Instance,FindPropInfo(Instance,PropName),Value);
  732. end;
  733. Procedure SetSetProp(Instance: TObject; const PropInfo: PPropInfo; const Value: string);
  734. begin
  735. SetOrdProp(Instance,PropInfo,StringToSet(PropInfo,Value));
  736. end;
  737. { ---------------------------------------------------------------------
  738. Object properties
  739. ---------------------------------------------------------------------}
  740. Function GetObjectProp(Instance: TObject; const PropName: string): TObject;
  741. begin
  742. Result:=GetObjectProp(Instance,PropName,Nil);
  743. end;
  744. Function GetObjectProp(Instance: TObject; const PropName: string; MinClass: TClass): TObject;
  745. begin
  746. Result:=GetObjectProp(Instance,FindPropInfo(Instance,PropName),MinClass);
  747. end;
  748. Function GetObjectProp(Instance: TObject; PropInfo : PPropInfo; MinClass: TClass): TObject;
  749. begin
  750. Result:=TObject(GetOrdProp(Instance,PropInfo));
  751. If (MinClass<>Nil) and (Result<>Nil) Then
  752. If Not Result.InheritsFrom(MinClass) then
  753. Result:=Nil;
  754. end;
  755. Procedure SetObjectProp(Instance: TObject; const PropName: string; Value: TObject);
  756. begin
  757. SetObjectProp(Instance,FindPropInfo(Instance,PropName),Value);
  758. end;
  759. Procedure SetObjectProp(Instance: TObject; PropInfo : PPropInfo; Value: TObject);
  760. begin
  761. SetOrdProp(Instance,PropInfo,Integer(Value));
  762. end;
  763. Function GetObjectPropClass(Instance: TObject; const PropName: string): TClass;
  764. begin
  765. Result:=GetTypeData(FindPropInfo(Instance,PropName)^.PropType)^.ClassType;
  766. end;
  767. { ---------------------------------------------------------------------
  768. String properties
  769. ---------------------------------------------------------------------}
  770. Function GetStrProp(Instance: TObject; PropInfo: PPropInfo): AnsiString;
  771. var
  772. Index, IValue: LongInt;
  773. ShortResult: ShortString;
  774. begin
  775. SetIndexValues(PropInfo, Index, IValue);
  776. case Propinfo^.PropType^.Kind of
  777. tkSString:
  778. case (PropInfo^.PropProcs) and 3 of
  779. ptField:
  780. Result := PShortString(Pointer(Instance) + LongWord(PropInfo^.GetProc))^;
  781. ptStatic:
  782. begin
  783. CallSStringFunc(Instance, PropInfo^.GetProc, Index, IValue, ShortResult);
  784. Result := ShortResult;
  785. end;
  786. ptVirtual:
  787. begin
  788. CallSStringFunc(Instance, PPointer(Pointer(Instance.ClassType) +
  789. LongWord(PropInfo^.GetProc))^, Index, IValue, ShortResult);
  790. Result := ShortResult;
  791. end;
  792. end;
  793. tkAString:
  794. case (PropInfo^.PropProcs) and 3 of
  795. ptField:
  796. Result := PAnsiString(Pointer(Instance) + LongWord(PropInfo^.GetProc))^;
  797. ptStatic:
  798. Pointer(Result) := Pointer(LongWord(CallIntegerFunc(Instance, PropInfo^.GetProc, Index, IValue)));
  799. ptVirtual:
  800. Pointer(Result) := Pointer(LongWord(CallIntegerFunc(Instance,
  801. PPointer(Pointer(Instance.ClassType) + LongWord(PropInfo^.GetProc))^, Index, IValue)));
  802. end;
  803. else
  804. // Property is neither of type AnsiString nor of type ShortString
  805. SetLength(Result, 0);
  806. end;
  807. end;
  808. Procedure SetAStrProp(Instance : TObject;PropInfo : PPropInfo;
  809. const Value : AnsiString);
  810. {
  811. Dirty trick based on fact that AnsiString is just a pointer,
  812. hence can be treated like an integer type.
  813. }
  814. var
  815. Index,Ivalue : Longint;
  816. begin
  817. SetIndexValues(PropInfo,Index,IValue);
  818. case (PropInfo^.PropProcs shr 2) and 3 of
  819. ptfield:
  820. PAnsiString(Pointer(Instance) + Longint(PropInfo^.SetProc))^ := Value;
  821. ptstatic:
  822. CallIntegerProc(Instance,PropInfo^.SetProc,Longint(Pointer(Value)),Index,IValue);
  823. ptvirtual:
  824. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Longint(Pointer(Value)),Index,IValue);
  825. end;
  826. end;
  827. Procedure SetSStrProp(Instance : TObject;PropInfo : PPropInfo;
  828. const Value : ShortString);
  829. Var Index,IValue: longint;
  830. begin
  831. SetIndexValues(PRopInfo,Index,IValue);
  832. case (PropInfo^.PropProcs shr 2) and 3 of
  833. ptfield:
  834. PShortString(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  835. ptstatic:
  836. CallSStringProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  837. ptvirtual:
  838. CallSStringProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  839. end;
  840. end;
  841. Procedure SetStrProp(Instance : TObject;PropInfo : PPropInfo;
  842. const Value : AnsiString);
  843. begin
  844. Case Propinfo^.PropType^.Kind of
  845. tkSString : SetSStrProp(Instance,PropInfo,Value);
  846. tkAString : SetAStrProp(Instance,Propinfo,Value);
  847. end;
  848. end;
  849. Function GetStrProp(Instance: TObject; const PropName: string): string;
  850. begin
  851. Result:=GetStrProp(Instance,FindPropInfo(Instance,PropName));
  852. end;
  853. Procedure SetStrProp(Instance: TObject; const PropName: string; const Value: AnsiString);
  854. begin
  855. SetStrProp(Instance,FindPropInfo(Instance,PropName),Value);
  856. end;
  857. { ---------------------------------------------------------------------
  858. Float properties
  859. ---------------------------------------------------------------------}
  860. Function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  861. var
  862. Index,Ivalue : longint;
  863. Value : Extended;
  864. begin
  865. SetIndexValues(PropInfo,Index,Ivalue);
  866. case (PropInfo^.PropProcs) and 3 of
  867. ptfield:
  868. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  869. ftSingle:
  870. Value:=PSingle(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  871. ftDouble:
  872. Value:=PDouble(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  873. ftExtended:
  874. Value:=PExtended(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  875. ftcomp:
  876. Value:=PComp(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  877. { Uncommenting this code results in a internal error!!
  878. ftFixed16:
  879. Value:=PFixed16(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  880. ftfixed32:
  881. Value:=PFixed32(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  882. }
  883. end;
  884. ptstatic:
  885. Value:=CallExtendedFunc(Instance,PropInfo^.GetProc,Index,IValue);
  886. ptvirtual:
  887. Value:=CallExtendedFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue);
  888. end;
  889. Result:=Value;
  890. end;
  891. Procedure SetFloatProp(Instance : TObject;PropInfo : PPropInfo;
  892. Value : Extended);
  893. Var IValue,Index : longint;
  894. begin
  895. SetIndexValues(PropInfo,Index,Ivalue);
  896. case (PropInfo^.PropProcs shr 2) and 3 of
  897. ptfield:
  898. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  899. ftSingle:
  900. PSingle(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  901. ftDouble:
  902. PDouble(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  903. ftExtended:
  904. PExtended(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  905. ftcomp:
  906. PComp(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Comp(Value);
  907. { Uncommenting this code results in a internal error!!
  908. ftFixed16:
  909. PFixed16(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  910. ftfixed32:
  911. PFixed32(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  912. }
  913. end;
  914. ptstatic:
  915. CallExtendedProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  916. ptvirtual:
  917. CallExtendedProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  918. end;
  919. end;
  920. Function GetFloatProp(Instance: TObject; const PropName: string): Extended;
  921. begin
  922. Result:=GetFloatProp(Instance,FindPropInfo(Instance,PropName))
  923. end;
  924. Procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Extended);
  925. begin
  926. SetFloatProp(Instance,FindPropInfo(Instance,PropName),Value);
  927. end;
  928. { ---------------------------------------------------------------------
  929. Variant properties
  930. ---------------------------------------------------------------------}
  931. Function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
  932. begin
  933. {!!!!!!!!!!!}
  934. Result:=nil;
  935. end;
  936. Procedure SetVariantProp(Instance : TObject;PropInfo : PPropInfo;
  937. const Value: Variant);
  938. begin
  939. {!!!!!!!!!!!}
  940. end;
  941. Function GetVariantProp(Instance: TObject; const PropName: string): Variant;
  942. begin
  943. Result:=GetVariantProp(Instance,FindPropInfo(Instance,PropName));
  944. end;
  945. Procedure SetVariantProp(Instance: TObject; const PropName: string; const Value: Variant);
  946. begin
  947. SetVariantprop(instance,FindpropInfo(Instance,PropName),Value);
  948. end;
  949. { ---------------------------------------------------------------------
  950. Method properties
  951. ---------------------------------------------------------------------}
  952. Function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  953. var
  954. value: PMethod;
  955. Index,Ivalue : longint;
  956. begin
  957. SetIndexValues(PropInfo,Index,Ivalue);
  958. case (PropInfo^.PropProcs) and 3 of
  959. ptfield:
  960. Value:=PMethod(Pointer(Instance)+Longint(PropInfo^.GetProc));
  961. ptstatic:
  962. Value:=PMethod(LongInt(CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue)));
  963. ptvirtual:
  964. Value:=PMethod(LongInt(CallIntegerFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue)));
  965. end;
  966. GetMethodProp:=Value^;
  967. end;
  968. Procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo;
  969. const Value : TMethod);
  970. var
  971. Index,IValue : Longint;
  972. begin
  973. SetIndexValues(PropInfo,Index,Ivalue);
  974. case (PropInfo^.PropProcs shr 2) and 3 of
  975. ptfield:
  976. PMethod(Pointer(Instance)+Longint(PropInfo^.SetProc))^ := Value;
  977. ptstatic:
  978. CallIntegerProc(Instance,PropInfo^.SetProc,Integer(@Value), Index, IValue);
  979. ptvirtual:
  980. CallIntegerProc(Instance,
  981. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,
  982. Integer(@Value), Index, IValue);
  983. end;
  984. end;
  985. Function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
  986. begin
  987. Result:=GetMethodProp(Instance,FindPropInfo(Instance,PropName));
  988. end;
  989. Procedure SetMethodProp(Instance: TObject; const PropName: string; const Value: TMethod);
  990. begin
  991. SetMethodProp(Instance,FindPropInfo(Instance,PropName),Value);
  992. end;
  993. { ---------------------------------------------------------------------
  994. Int64 properties
  995. ---------------------------------------------------------------------}
  996. Function GetInt64Prop(Instance: TObject; PropInfo: PPropInfo): Int64;
  997. var
  998. Index, IValue: LongInt;
  999. begin
  1000. SetIndexValues(PropInfo,Index,Ivalue);
  1001. case PropInfo^.PropProcs and 3 of
  1002. ptfield:
  1003. Result := PInt64(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  1004. ptstatic:
  1005. Result := CallIntegerFunc(Instance, PropInfo^.GetProc, Index, IValue);
  1006. ptvirtual:
  1007. Result := CallIntegerFunc(Instance,
  1008. PPointer(Pointer(Instance.ClassType) + LongInt(PropInfo^.GetProc))^,
  1009. Index, IValue);
  1010. end;
  1011. end;
  1012. procedure SetInt64Prop(Instance: TObject; PropInfo: PPropInfo; const Value: Int64);
  1013. var
  1014. Index, IValue: LongInt;
  1015. begin
  1016. SetIndexValues(PropInfo,Index,Ivalue);
  1017. case PropInfo^.PropProcs and 3 of
  1018. ptfield:
  1019. PInt64(Pointer(Instance)+Longint(PropInfo^.GetProc))^ := Value;
  1020. ptstatic:
  1021. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  1022. ptvirtual:
  1023. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  1024. end;
  1025. end;
  1026. Function GetInt64Prop(Instance: TObject; const PropName: string): Int64;
  1027. begin
  1028. Result:=GetInt64Prop(Instance,FindPropInfo(Instance,PropName));
  1029. end;
  1030. Procedure SetInt64Prop(Instance: TObject; const PropName: string; const Value: Int64);
  1031. begin
  1032. SetInt64Prop(Instance,FindPropInfo(Instance,PropName),Value);
  1033. end;
  1034. { ---------------------------------------------------------------------
  1035. All properties through variant.
  1036. ---------------------------------------------------------------------}
  1037. Function GetPropValue(Instance: TObject; const PropName: string): Variant;
  1038. begin
  1039. Result:=GetPropValue(Instance,PropName,True);
  1040. end;
  1041. Function GetPropValue(Instance: TObject; const PropName: string; PreferStrings: Boolean): Variant;
  1042. begin
  1043. end;
  1044. Procedure SetPropValue(Instance: TObject; const PropName: string; const Value: Variant);
  1045. begin
  1046. end;
  1047. { ---------------------------------------------------------------------
  1048. Easy access methods that appeared in Delphi 5
  1049. ---------------------------------------------------------------------}
  1050. Function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
  1051. begin
  1052. Result:=GetPropInfo(Instance,PropName)<>Nil;
  1053. end;
  1054. Function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;
  1055. begin
  1056. Result:=GetPropInfo(AClass,PropName)<>Nil;
  1057. end;
  1058. Function PropIsType(Instance: TObject; const PropName: string; TypeKind: TTypeKind): Boolean;
  1059. begin
  1060. Result:=FindPropInfo(Instance,PropName)^.PropType^.Kind=TypeKind
  1061. end;
  1062. Function PropIsType(AClass: TClass; const PropName: string; TypeKind: TTypeKind): Boolean;
  1063. begin
  1064. Result:=PropType(AClass,PropName)=TypeKind
  1065. end;
  1066. Function PropType(Instance: TObject; const PropName: string): TTypeKind;
  1067. begin
  1068. Result:=FindPropInfo(Instance,PropName)^.PropType^.Kind;
  1069. end;
  1070. Function PropType(AClass: TClass; const PropName: string): TTypeKind;
  1071. begin
  1072. Result:=FindPropInfo(AClass,PropName)^.PropType^.Kind;
  1073. end;
  1074. Function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
  1075. begin
  1076. Result:=IsStoredProp(instance,FindPropInfo(Instance,PropName));
  1077. end;
  1078. end.
  1079. {
  1080. $Log$
  1081. Revision 1.11 2001-07-29 13:50:44 peter
  1082. * merged updates from v10
  1083. Revision 1.9 2001/07/06 14:56:06 peter
  1084. * merged more D5/D6 stuff from v10
  1085. Revision 1.8 2001/06/27 21:37:38 peter
  1086. * v10 merges
  1087. Revision 1.7 2001/02/15 22:40:22 sg
  1088. * Fixed SetOrdProp for class instance properties (merged from fixbranch)
  1089. Revision 1.6 2000/12/13 23:28:17 sg
  1090. * Merged bugfix for bug 1273 from fixbranch
  1091. * Fixed typo in SetFloatProp
  1092. * Rewrote GetStrProp, now all AnsiString will be correctly
  1093. reference counted
  1094. Revision 1.5 2000/11/25 18:36:55 sg
  1095. * (Final) fix for AnsiString reference counter problem in SetStrProp
  1096. Revision 1.4 2000/11/04 16:28:26 florian
  1097. * interfaces support
  1098. Revision 1.3 2000/07/17 08:37:58 sg
  1099. * Fixed GetEnumValue (bug #1049, reported by Neil Graham)
  1100. Revision 1.2 2000/07/13 11:33:52 michael
  1101. + removed logs
  1102. }