typinfo.pp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  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. {$I typinfo.inc}
  333. { ---------------------------------------------------------------------
  334. Basic Type information functions.
  335. ---------------------------------------------------------------------}
  336. Function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string) : PPropInfo;
  337. var
  338. hp : PTypeData;
  339. i : longint;
  340. p : string;
  341. pd : ^TPropData;
  342. begin
  343. P:=UpCase(PropName);
  344. while Assigned(TypeInfo) do
  345. begin
  346. // skip the name
  347. hp:=GetTypeData(Typeinfo);
  348. // the class info rtti the property rtti follows immediatly
  349. pd:=pointer(pointer(@hp^.UnitName)+Length(hp^.UnitName)+1);
  350. Result:=@pd^.PropList;
  351. for i:=1 to pd^.PropCount do
  352. begin
  353. // found a property of that name ?
  354. if Upcase(Result^.Name)=P then
  355. exit;
  356. // skip to next property
  357. Result:=PPropInfo(pointer(@Result^.Name)+byte(Result^.Name[0])+1);
  358. end;
  359. // parent class
  360. Typeinfo:=hp^.ParentInfo;
  361. end;
  362. Result:=Nil;
  363. end;
  364. Function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string; Akinds : TTypeKinds) : PPropInfo;
  365. begin
  366. Result:=GetPropInfo(TypeInfo,PropName);
  367. If (Akinds<>[]) then
  368. If (Result<>Nil) then
  369. If Not (Result^.PropType^.Kind in AKinds) then
  370. Result:=Nil;
  371. end;
  372. Function GetPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  373. begin
  374. Result:=GetPropInfo(PTypeInfo(AClass.ClassInfo),PropName,AKinds);
  375. end;
  376. Function GetPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  377. begin
  378. Result:=GetPropInfo(Instance.ClassType,PropName,AKinds);
  379. end;
  380. Function GetPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  381. begin
  382. Result:=GetPropInfo(Instance,PropName,[]);
  383. end;
  384. Function GetPropInfo(AClass: TClass; const PropName: string): PPropInfo;
  385. begin
  386. Result:=GetPropInfo(AClass,PropName,[]);
  387. end;
  388. Function FindPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  389. begin
  390. result:=GetPropInfo(Instance, PropName);
  391. if Result=nil then
  392. Raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
  393. end;
  394. Function FindPropInfo(AClass:TClass;const PropName: string): PPropInfo;
  395. begin
  396. result:=GetPropInfo(AClass,PropName);
  397. if result=nil then
  398. Raise EPropertyError.CreateFmt(SErrPropertyNotFound, [PropName]);
  399. end;
  400. Function IsStoredProp(Instance : TObject;PropInfo : PPropInfo) : Boolean;
  401. begin
  402. case (PropInfo^.PropProcs shr 4) and 3 of
  403. ptfield:
  404. IsStoredProp:=PBoolean(Pointer(Instance)+Longint(PropInfo^.StoredProc))^;
  405. ptstatic:
  406. IsStoredProp:=CallBooleanFunc(Instance,PropInfo^.StoredProc,0,0);
  407. ptvirtual:
  408. IsStoredProp:=CallBooleanFunc(Instance,ppointer(Pointer(Instance.ClassType)+Longint(PropInfo^.StoredProc))^,0,0);
  409. ptconst:
  410. IsStoredProp:=LongBool(PropInfo^.StoredProc);
  411. end;
  412. end;
  413. Procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
  414. {
  415. Store Pointers to property information in the list pointed
  416. to by proplist. PRopList must contain enough space to hold ALL
  417. properties.
  418. }
  419. Type PWord = ^Word;
  420. Var TD : PTypeData;
  421. TP : PPropInfo;
  422. Count : Longint;
  423. begin
  424. TD:=GetTypeData(TypeInfo);
  425. // Get this objects TOTAL published properties count
  426. TP:=(@TD^.UnitName+Length(TD^.UnitName)+1);
  427. Count:=PWord(TP)^;
  428. // Now point TP to first propinfo record.
  429. Inc(Longint(TP),SizeOF(Word));
  430. While Count>0 do
  431. begin
  432. PropList^[0]:=TP;
  433. Inc(Longint(PropList),SizeOf(Pointer));
  434. // Point to TP next propinfo record.
  435. // Located at Name[Length(Name)+1] !
  436. TP:=PPropInfo(pointer(@TP^.Name)+PByte(@TP^.Name)^+1);
  437. Dec(Count);
  438. end;
  439. // recursive call for parent info.
  440. If TD^.Parentinfo<>Nil then
  441. GetPropInfos (TD^.ParentInfo,PropList);
  442. end;
  443. Procedure InsertProp (PL : PProplist;PI : PPropInfo; Count : longint);
  444. Var I : Longint;
  445. begin
  446. I:=0;
  447. While (I<Count) and (PI^.Name>PL^[I]^.Name) do Inc(I);
  448. If I<Count then
  449. Move(PL^[I], PL^[I+1], (Count - I) * SizeOf(Pointer));
  450. PL^[I]:=PI;
  451. end;
  452. Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds;
  453. PropList : PPropList) : Integer;
  454. {
  455. Store Pointers to property information OF A CERTAIN KIND in the list pointed
  456. to by proplist. PRopList must contain enough space to hold ALL
  457. properties.
  458. }
  459. Var TempList : PPropList;
  460. PropInfo : PPropinfo;
  461. I,Count : longint;
  462. begin
  463. Result:=0;
  464. Count:=GetTypeData(TypeInfo)^.Propcount;
  465. If Count>0 then
  466. begin
  467. GetMem(TempList,Count*SizeOf(Pointer));
  468. Try
  469. GetPropInfos(TypeInfo,TempList);
  470. For I:=0 to Count-1 do
  471. begin
  472. PropInfo:=TempList^[i];
  473. If PropInfo^.PropType^.Kind in TypeKinds then
  474. begin
  475. InsertProp(PropList,PropInfo,Result);
  476. Inc(Result);
  477. end;
  478. end;
  479. finally
  480. FreeMem(TempList,Count*SizeOf(Pointer));
  481. end;
  482. end;
  483. end;
  484. Procedure SetIndexValues (P: PPRopInfo; Var Index,IValue : Longint);
  485. begin
  486. Index:=((P^.PropProcs shr 6) and 1);
  487. If Index<>0 then
  488. IValue:=P^.Index
  489. else
  490. IValue:=0;
  491. end;
  492. { ---------------------------------------------------------------------
  493. Property access functions
  494. ---------------------------------------------------------------------}
  495. { ---------------------------------------------------------------------
  496. Ordinal properties
  497. ---------------------------------------------------------------------}
  498. Function GetOrdProp(Instance : TObject;PropInfo : PPropInfo) : Longint;
  499. var
  500. value,Index,Ivalue : longint;
  501. TypeInfo: PTypeInfo;
  502. begin
  503. SetIndexValues(PropInfo,Index,Ivalue);
  504. case (PropInfo^.PropProcs) and 3 of
  505. ptfield:
  506. Value:=PLongint(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  507. ptstatic:
  508. Value:=CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue);
  509. ptvirtual:
  510. Value:=CallIntegerFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue);
  511. end;
  512. { cut off unnecessary stuff }
  513. TypeInfo := PropInfo^.PropType;
  514. case TypeInfo^.Kind of
  515. tkChar, tkBool:
  516. Value:=Value and $ff;
  517. tkWChar:
  518. Value:=Value and $ffff;
  519. tkEnumeration,
  520. tkInteger:
  521. case GetTypeData(TypeInfo)^.OrdType of
  522. otSWord,otUWord:
  523. Value:=Value and $ffff;
  524. otSByte,otUByte:
  525. Value:=Value and $ff;
  526. end;
  527. end;
  528. GetOrdProp:=Value;
  529. end;
  530. Procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;
  531. Value : Longint);
  532. var
  533. Index,IValue : Longint;
  534. DataSize: Integer;
  535. begin
  536. if PropInfo^.PropType^.Kind <> tkClass then
  537. { cut off unnecessary stuff }
  538. case GetTypeData(PropInfo^.PropType)^.OrdType of
  539. otSWord,otUWord:
  540. begin
  541. Value:=Value and $ffff;
  542. DataSize := 2;
  543. end;
  544. otSByte,otUByte:
  545. begin
  546. Value:=Value and $ff;
  547. DataSize := 1;
  548. end;
  549. else
  550. DataSize := 4;
  551. end
  552. else
  553. DataSize := 4;
  554. SetIndexValues(PropInfo,Index,Ivalue);
  555. case (PropInfo^.PropProcs shr 2) and 3 of
  556. ptfield:
  557. case DataSize of
  558. 1: PByte(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Byte(Value);
  559. 2: PWord(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Word(Value);
  560. 4: PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  561. end;
  562. ptstatic:
  563. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  564. ptvirtual:
  565. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  566. end;
  567. end;
  568. Function GetOrdProp(Instance: TObject; const PropName: string): Longint;
  569. begin
  570. Result:=GetOrdProp(Instance,FindPropInfo(Instance,PropName));
  571. end;
  572. Procedure SetOrdProp(Instance: TObject; const PropName: string; Value: Longint);
  573. begin
  574. SetOrdProp(Instance,FindPropInfo(Instance,PropName),Value);
  575. end;
  576. Function GetEnumProp(Instance: TObject; Const PropInfo: PPropInfo): string;
  577. begin
  578. Result:=GetEnumName(PropInfo^.PropType, GetOrdProp(Instance, PropInfo));
  579. end;
  580. Function GetEnumProp(Instance: TObject; const PropName: string): string;
  581. begin
  582. Result:=GetEnumProp(Instance,FindPropInfo(Instance,PropName));
  583. end;
  584. Procedure SetEnumProp(Instance: TObject; const PropName: string; const Value: string);
  585. begin
  586. SetEnumProp(Instance,FindPropInfo(Instance,PropName),Value);
  587. end;
  588. Procedure SetEnumProp(Instance: TObject; Const PropInfo : PPropInfo; const Value: string);
  589. Var
  590. PV : Longint;
  591. begin
  592. If PropInfo<>Nil then
  593. begin
  594. PV:=GetEnumValue(PropInfo^.PropType, Value);
  595. if (PV<0) then
  596. raise EPropertyError.CreateFmt(SErrUnknownEnumValue, [Value]);
  597. SetOrdProp(Instance, PropInfo,PV);
  598. end;
  599. end;
  600. { ---------------------------------------------------------------------
  601. Set properties
  602. ---------------------------------------------------------------------}
  603. Function GetSetProp(Instance: TObject; const PropName: string): string;
  604. begin
  605. Result:=GetSetProp(Instance,PropName,False);
  606. end;
  607. Function GetSetProp(Instance: TObject; const PropName: string; Brackets: Boolean): string;
  608. begin
  609. Result:=GetSetProp(Instance,FindPropInfo(Instance,PropName),Brackets);
  610. end;
  611. Function GetSetProp(Instance: TObject; const PropInfo: PPropInfo; Brackets: Boolean): string;
  612. begin
  613. Result:=SetToString(PropInfo,GetOrdProp(Instance,PropInfo),Brackets);
  614. end;
  615. Procedure SetSetProp(Instance: TObject; const PropName: string; const Value: string);
  616. begin
  617. SetSetProp(Instance,FindPropInfo(Instance,PropName),Value);
  618. end;
  619. Procedure SetSetProp(Instance: TObject; const PropInfo: PPropInfo; const Value: string);
  620. begin
  621. SetOrdProp(Instance,PropInfo,StringToSet(PropInfo,Value));
  622. end;
  623. { ---------------------------------------------------------------------
  624. Object properties
  625. ---------------------------------------------------------------------}
  626. Function GetObjectProp(Instance: TObject; const PropName: string): TObject;
  627. begin
  628. Result:=GetObjectProp(Instance,PropName,Nil);
  629. end;
  630. Function GetObjectProp(Instance: TObject; const PropName: string; MinClass: TClass): TObject;
  631. begin
  632. Result:=GetObjectProp(Instance,FindPropInfo(Instance,PropName),MinClass);
  633. end;
  634. Function GetObjectProp(Instance: TObject; PropInfo : PPropInfo; MinClass: TClass): TObject;
  635. begin
  636. Result:=TObject(GetOrdProp(Instance,PropInfo));
  637. If (MinClass<>Nil) and (Result<>Nil) Then
  638. If Not Result.InheritsFrom(MinClass) then
  639. Result:=Nil;
  640. end;
  641. Procedure SetObjectProp(Instance: TObject; const PropName: string; Value: TObject);
  642. begin
  643. SetObjectProp(Instance,FindPropInfo(Instance,PropName),Value);
  644. end;
  645. Procedure SetObjectProp(Instance: TObject; PropInfo : PPropInfo; Value: TObject);
  646. begin
  647. SetOrdProp(Instance,PropInfo,Integer(Value));
  648. end;
  649. Function GetObjectPropClass(Instance: TObject; const PropName: string): TClass;
  650. begin
  651. Result:=GetTypeData(FindPropInfo(Instance,PropName)^.PropType)^.ClassType;
  652. end;
  653. { ---------------------------------------------------------------------
  654. String properties
  655. ---------------------------------------------------------------------}
  656. Function GetStrProp(Instance: TObject; PropInfo: PPropInfo): AnsiString;
  657. var
  658. Index, IValue: LongInt;
  659. ShortResult: ShortString;
  660. begin
  661. SetIndexValues(PropInfo, Index, IValue);
  662. case Propinfo^.PropType^.Kind of
  663. tkSString:
  664. case (PropInfo^.PropProcs) and 3 of
  665. ptField:
  666. Result := PShortString(Pointer(Instance) + LongWord(PropInfo^.GetProc))^;
  667. ptStatic:
  668. begin
  669. CallSStringFunc(Instance, PropInfo^.GetProc, Index, IValue, ShortResult);
  670. Result := ShortResult;
  671. end;
  672. ptVirtual:
  673. begin
  674. CallSStringFunc(Instance, PPointer(Pointer(Instance.ClassType) +
  675. LongWord(PropInfo^.GetProc))^, Index, IValue, ShortResult);
  676. Result := ShortResult;
  677. end;
  678. end;
  679. tkAString:
  680. case (PropInfo^.PropProcs) and 3 of
  681. ptField:
  682. Result := PAnsiString(Pointer(Instance) + LongWord(PropInfo^.GetProc))^;
  683. ptStatic:
  684. Pointer(Result) := Pointer(LongWord(CallIntegerFunc(Instance, PropInfo^.GetProc, Index, IValue)));
  685. ptVirtual:
  686. Pointer(Result) := Pointer(LongWord(CallIntegerFunc(Instance,
  687. PPointer(Pointer(Instance.ClassType) + LongWord(PropInfo^.GetProc))^, Index, IValue)));
  688. end;
  689. else
  690. // Property is neither of type AnsiString nor of type ShortString
  691. SetLength(Result, 0);
  692. end;
  693. end;
  694. Procedure SetAStrProp(Instance : TObject;PropInfo : PPropInfo;
  695. const Value : AnsiString);
  696. {
  697. Dirty trick based on fact that AnsiString is just a pointer,
  698. hence can be treated like an integer type.
  699. }
  700. var
  701. Index,Ivalue : Longint;
  702. begin
  703. SetIndexValues(PropInfo,Index,IValue);
  704. case (PropInfo^.PropProcs shr 2) and 3 of
  705. ptfield:
  706. PAnsiString(Pointer(Instance) + Longint(PropInfo^.SetProc))^ := Value;
  707. ptstatic:
  708. CallIntegerProc(Instance,PropInfo^.SetProc,Longint(Pointer(Value)),Index,IValue);
  709. ptvirtual:
  710. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Longint(Pointer(Value)),Index,IValue);
  711. end;
  712. end;
  713. Procedure SetSStrProp(Instance : TObject;PropInfo : PPropInfo;
  714. const Value : ShortString);
  715. Var Index,IValue: longint;
  716. begin
  717. SetIndexValues(PRopInfo,Index,IValue);
  718. case (PropInfo^.PropProcs shr 2) and 3 of
  719. ptfield:
  720. PShortString(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  721. ptstatic:
  722. CallSStringProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  723. ptvirtual:
  724. CallSStringProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  725. end;
  726. end;
  727. Procedure SetStrProp(Instance : TObject;PropInfo : PPropInfo;
  728. const Value : AnsiString);
  729. begin
  730. Case Propinfo^.PropType^.Kind of
  731. tkSString : SetSStrProp(Instance,PropInfo,Value);
  732. tkAString : SetAStrProp(Instance,Propinfo,Value);
  733. end;
  734. end;
  735. Function GetStrProp(Instance: TObject; const PropName: string): string;
  736. begin
  737. Result:=GetStrProp(Instance,FindPropInfo(Instance,PropName));
  738. end;
  739. Procedure SetStrProp(Instance: TObject; const PropName: string; const Value: AnsiString);
  740. begin
  741. SetStrProp(Instance,FindPropInfo(Instance,PropName),Value);
  742. end;
  743. { ---------------------------------------------------------------------
  744. Float properties
  745. ---------------------------------------------------------------------}
  746. Function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  747. var
  748. Index,Ivalue : longint;
  749. Value : Extended;
  750. begin
  751. SetIndexValues(PropInfo,Index,Ivalue);
  752. case (PropInfo^.PropProcs) and 3 of
  753. ptField:
  754. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  755. ftSingle:
  756. Value:=PSingle(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  757. ftDouble:
  758. Value:=PDouble(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  759. ftExtended:
  760. Value:=PExtended(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  761. {$ifndef cpum68k}
  762. ftcomp:
  763. Value:=PComp(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  764. {$endif cpum68k}
  765. end;
  766. ptStatic:
  767. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  768. ftSingle:
  769. Value:=CallSingleFunc(Instance,PropInfo^.GetProc,Index,IValue);
  770. ftDouble:
  771. Value:=CallDoubleFunc(Instance,PropInfo^.GetProc,Index,IValue);
  772. ftExtended:
  773. Value:=CallExtendedFunc(Instance,PropInfo^.GetProc,Index,IValue);
  774. end;
  775. ptVirtual:
  776. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  777. ftSingle:
  778. Value:=CallSingleFunc(Instance,
  779. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,
  780. Index,IValue);
  781. ftDouble:
  782. Value:=CallDoubleFunc(Instance,
  783. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,
  784. Index,IValue);
  785. ftExtended:
  786. Value:=CallExtendedFunc(Instance,
  787. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,
  788. Index,IValue);
  789. end;
  790. end;
  791. Result:=Value;
  792. end;
  793. Procedure SetFloatProp(Instance : TObject;PropInfo : PPropInfo;
  794. Value : Extended);
  795. type
  796. TSetExtendedProc = procedure(const AValue: Extended) of object;
  797. TSetExtendedProcIndex = procedure(Index: integer; const AValue: Extended) of object;
  798. TSetDoubleProc = procedure(const AValue: Double) of object;
  799. TSetDoubleProcIndex = procedure(Index: integer; const AValue: Double) of object;
  800. TSetSingleProc = procedure(const AValue: Single) of object;
  801. TSetSingleProcIndex = procedure(Index: integer; const AValue: Single) of object;
  802. Var IValue,Index : longint;
  803. AMethod: TMethod;
  804. begin
  805. SetIndexValues(PropInfo,Index,Ivalue);
  806. case (PropInfo^.PropProcs shr 2) and 3 of
  807. ptfield:
  808. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  809. ftSingle:
  810. PSingle(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  811. ftDouble:
  812. PDouble(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  813. ftExtended:
  814. PExtended(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  815. {$ifndef cpum68k}
  816. ftcomp:
  817. PComp(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Comp(Value);
  818. {$endif cpum68k}
  819. { Uncommenting this code results in a internal error!!
  820. ftFixed16:
  821. PFixed16(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  822. ftfixed32:
  823. PFixed32(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  824. }
  825. end;
  826. ptStatic, ptVirtual:
  827. begin
  828. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  829. AMethod.Code:=PropInfo^.SetProc
  830. else
  831. AMethod.Code:=
  832. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^;
  833. AMethod.Data:=Instance;
  834. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  835. ftSingle:
  836. if Index=0 then
  837. TSetSingleProc(AMethod)(Value)
  838. else
  839. TSetSingleProcIndex(AMethod)(IValue,Value);
  840. ftDouble:
  841. if Index=0 then
  842. TSetDoubleProc(AMethod)(Value)
  843. else
  844. TSetDoubleProcIndex(AMethod)(IValue,Value);
  845. ftExtended:
  846. if Index=0 then
  847. TSetExtendedProc(AMethod)(Value)
  848. else
  849. TSetExtendedProcIndex(AMethod)(IValue,Value);
  850. end;
  851. end;
  852. end;
  853. end;
  854. Function GetFloatProp(Instance: TObject; const PropName: string): Extended;
  855. begin
  856. Result:=GetFloatProp(Instance,FindPropInfo(Instance,PropName))
  857. end;
  858. Procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Extended);
  859. begin
  860. SetFloatProp(Instance,FindPropInfo(Instance,PropName),Value);
  861. end;
  862. { ---------------------------------------------------------------------
  863. Variant properties
  864. ---------------------------------------------------------------------}
  865. Function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
  866. begin
  867. {!!!!!!!!!!!}
  868. Result:=nil;
  869. end;
  870. Procedure SetVariantProp(Instance : TObject;PropInfo : PPropInfo;
  871. const Value: Variant);
  872. begin
  873. {!!!!!!!!!!!}
  874. end;
  875. Function GetVariantProp(Instance: TObject; const PropName: string): Variant;
  876. begin
  877. Result:=GetVariantProp(Instance,FindPropInfo(Instance,PropName));
  878. end;
  879. Procedure SetVariantProp(Instance: TObject; const PropName: string; const Value: Variant);
  880. begin
  881. SetVariantprop(instance,FindpropInfo(Instance,PropName),Value);
  882. end;
  883. { ---------------------------------------------------------------------
  884. Method properties
  885. ---------------------------------------------------------------------}
  886. Function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  887. var
  888. value: PMethod;
  889. Index,Ivalue : longint;
  890. begin
  891. SetIndexValues(PropInfo,Index,Ivalue);
  892. case (PropInfo^.PropProcs) and 3 of
  893. ptfield:
  894. Value:=PMethod(Pointer(Instance)+Longint(PropInfo^.GetProc));
  895. ptstatic:
  896. Value:=PMethod(LongInt(CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue)));
  897. ptvirtual:
  898. Value:=PMethod(LongInt(CallIntegerFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue)));
  899. end;
  900. GetMethodProp:=Value^;
  901. end;
  902. Procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo;
  903. const Value : TMethod);
  904. var
  905. Index,IValue : Longint;
  906. begin
  907. SetIndexValues(PropInfo,Index,Ivalue);
  908. case (PropInfo^.PropProcs shr 2) and 3 of
  909. ptfield:
  910. PMethod(Pointer(Instance)+Longint(PropInfo^.SetProc))^ := Value;
  911. ptstatic:
  912. CallIntegerProc(Instance,PropInfo^.SetProc,Integer(@Value), Index, IValue);
  913. ptvirtual:
  914. CallIntegerProc(Instance,
  915. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,
  916. Integer(@Value), Index, IValue);
  917. end;
  918. end;
  919. Function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
  920. begin
  921. Result:=GetMethodProp(Instance,FindPropInfo(Instance,PropName));
  922. end;
  923. Procedure SetMethodProp(Instance: TObject; const PropName: string; const Value: TMethod);
  924. begin
  925. SetMethodProp(Instance,FindPropInfo(Instance,PropName),Value);
  926. end;
  927. { ---------------------------------------------------------------------
  928. Int64 properties
  929. ---------------------------------------------------------------------}
  930. Function GetInt64Prop(Instance: TObject; PropInfo: PPropInfo): Int64;
  931. var
  932. Index, IValue: LongInt;
  933. begin
  934. SetIndexValues(PropInfo,Index,Ivalue);
  935. case PropInfo^.PropProcs and 3 of
  936. ptfield:
  937. Result := PInt64(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  938. ptstatic:
  939. Result := CallIntegerFunc(Instance, PropInfo^.GetProc, Index, IValue);
  940. ptvirtual:
  941. Result := CallIntegerFunc(Instance,
  942. PPointer(Pointer(Instance.ClassType) + LongInt(PropInfo^.GetProc))^,
  943. Index, IValue);
  944. end;
  945. end;
  946. procedure SetInt64Prop(Instance: TObject; PropInfo: PPropInfo; const Value: Int64);
  947. var
  948. Index, IValue: LongInt;
  949. begin
  950. SetIndexValues(PropInfo,Index,Ivalue);
  951. case PropInfo^.PropProcs and 3 of
  952. ptfield:
  953. PInt64(Pointer(Instance)+Longint(PropInfo^.GetProc))^ := Value;
  954. ptstatic:
  955. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  956. ptvirtual:
  957. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  958. end;
  959. end;
  960. Function GetInt64Prop(Instance: TObject; const PropName: string): Int64;
  961. begin
  962. Result:=GetInt64Prop(Instance,FindPropInfo(Instance,PropName));
  963. end;
  964. Procedure SetInt64Prop(Instance: TObject; const PropName: string; const Value: Int64);
  965. begin
  966. SetInt64Prop(Instance,FindPropInfo(Instance,PropName),Value);
  967. end;
  968. { ---------------------------------------------------------------------
  969. All properties through variant.
  970. ---------------------------------------------------------------------}
  971. Function GetPropValue(Instance: TObject; const PropName: string): Variant;
  972. begin
  973. Result:=GetPropValue(Instance,PropName,True);
  974. end;
  975. Function GetPropValue(Instance: TObject; const PropName: string; PreferStrings: Boolean): Variant;
  976. begin
  977. end;
  978. Procedure SetPropValue(Instance: TObject; const PropName: string; const Value: Variant);
  979. begin
  980. end;
  981. { ---------------------------------------------------------------------
  982. Easy access methods that appeared in Delphi 5
  983. ---------------------------------------------------------------------}
  984. Function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
  985. begin
  986. Result:=GetPropInfo(Instance,PropName)<>Nil;
  987. end;
  988. Function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;
  989. begin
  990. Result:=GetPropInfo(AClass,PropName)<>Nil;
  991. end;
  992. Function PropIsType(Instance: TObject; const PropName: string; TypeKind: TTypeKind): Boolean;
  993. begin
  994. Result:=FindPropInfo(Instance,PropName)^.PropType^.Kind=TypeKind
  995. end;
  996. Function PropIsType(AClass: TClass; const PropName: string; TypeKind: TTypeKind): Boolean;
  997. begin
  998. Result:=PropType(AClass,PropName)=TypeKind
  999. end;
  1000. Function PropType(Instance: TObject; const PropName: string): TTypeKind;
  1001. begin
  1002. Result:=FindPropInfo(Instance,PropName)^.PropType^.Kind;
  1003. end;
  1004. Function PropType(AClass: TClass; const PropName: string): TTypeKind;
  1005. begin
  1006. Result:=FindPropInfo(AClass,PropName)^.PropType^.Kind;
  1007. end;
  1008. Function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
  1009. begin
  1010. Result:=IsStoredProp(instance,FindPropInfo(Instance,PropName));
  1011. end;
  1012. end.
  1013. {
  1014. $Log$
  1015. Revision 1.18 2003-10-24 08:37:20 marco
  1016. * Fix from Peter
  1017. Revision 1.17 2003/10/17 20:58:27 olle
  1018. * Changed m68k to cpum68k, i386 to cpui386
  1019. Revision 1.16 2003/04/24 11:46:25 florian
  1020. * fixed wrong newlines
  1021. Revision 1.15 2003/03/29 16:55:56 michael
  1022. + Patch from Mattias Gaertner for single typeinfo
  1023. Revision 1.14 2002/09/07 16:01:22 peter
  1024. * old logs removed and tabs fixed
  1025. Revision 1.13 2002/04/04 18:32:59 peter
  1026. * merged getpropinfo fix
  1027. }