typinfo.pp 42 KB

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