typinfo.pp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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. tkInteger:
  520. case GetTypeData(TypeInfo)^.OrdType of
  521. otSWord,otUWord:
  522. Value:=Value and $ffff;
  523. otSByte,otUByte:
  524. Value:=Value and $ff;
  525. end;
  526. end;
  527. GetOrdProp:=Value;
  528. end;
  529. Procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;
  530. Value : Longint);
  531. var
  532. Index,IValue : Longint;
  533. DataSize: Integer;
  534. begin
  535. if PropInfo^.PropType^.Kind <> tkClass then
  536. { cut off unnecessary stuff }
  537. case GetTypeData(PropInfo^.PropType)^.OrdType of
  538. otSWord,otUWord:
  539. begin
  540. Value:=Value and $ffff;
  541. DataSize := 2;
  542. end;
  543. otSByte,otUByte:
  544. begin
  545. Value:=Value and $ff;
  546. DataSize := 1;
  547. end;
  548. else
  549. DataSize := 4;
  550. end
  551. else
  552. DataSize := 4;
  553. SetIndexValues(PropInfo,Index,Ivalue);
  554. case (PropInfo^.PropProcs shr 2) and 3 of
  555. ptfield:
  556. case DataSize of
  557. 1: PByte(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Byte(Value);
  558. 2: PWord(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Word(Value);
  559. 4: PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  560. end;
  561. ptstatic:
  562. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  563. ptvirtual:
  564. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  565. end;
  566. end;
  567. Function GetOrdProp(Instance: TObject; const PropName: string): Longint;
  568. begin
  569. Result:=GetOrdProp(Instance,FindPropInfo(Instance,PropName));
  570. end;
  571. Procedure SetOrdProp(Instance: TObject; const PropName: string; Value: Longint);
  572. begin
  573. SetOrdProp(Instance,FindPropInfo(Instance,PropName),Value);
  574. end;
  575. Function GetEnumProp(Instance: TObject; Const PropInfo: PPropInfo): string;
  576. begin
  577. Result:=GetEnumName(PropInfo^.PropType, GetOrdProp(Instance, PropInfo));
  578. end;
  579. Function GetEnumProp(Instance: TObject; const PropName: string): string;
  580. begin
  581. Result:=GetEnumProp(Instance,FindPropInfo(Instance,PropName));
  582. end;
  583. Procedure SetEnumProp(Instance: TObject; const PropName: string; const Value: string);
  584. begin
  585. SetEnumProp(Instance,FindPropInfo(Instance,PropName),Value);
  586. end;
  587. Procedure SetEnumProp(Instance: TObject; Const PropInfo : PPropInfo; const Value: string);
  588. Var
  589. PV : Longint;
  590. begin
  591. If PropInfo<>Nil then
  592. begin
  593. PV:=GetEnumValue(PropInfo^.PropType, Value);
  594. if (PV<0) then
  595. raise EPropertyError.CreateFmt(SErrUnknownEnumValue, [Value]);
  596. SetOrdProp(Instance, PropInfo,PV);
  597. end;
  598. end;
  599. { ---------------------------------------------------------------------
  600. Set properties
  601. ---------------------------------------------------------------------}
  602. Function GetSetProp(Instance: TObject; const PropName: string): string;
  603. begin
  604. Result:=GetSetProp(Instance,PropName,False);
  605. end;
  606. Function GetSetProp(Instance: TObject; const PropName: string; Brackets: Boolean): string;
  607. begin
  608. Result:=GetSetProp(Instance,FindPropInfo(Instance,PropName),Brackets);
  609. end;
  610. Function GetSetProp(Instance: TObject; const PropInfo: PPropInfo; Brackets: Boolean): string;
  611. begin
  612. Result:=SetToString(PropInfo,GetOrdProp(Instance,PropInfo),Brackets);
  613. end;
  614. Procedure SetSetProp(Instance: TObject; const PropName: string; const Value: string);
  615. begin
  616. SetSetProp(Instance,FindPropInfo(Instance,PropName),Value);
  617. end;
  618. Procedure SetSetProp(Instance: TObject; const PropInfo: PPropInfo; const Value: string);
  619. begin
  620. SetOrdProp(Instance,PropInfo,StringToSet(PropInfo,Value));
  621. end;
  622. { ---------------------------------------------------------------------
  623. Object properties
  624. ---------------------------------------------------------------------}
  625. Function GetObjectProp(Instance: TObject; const PropName: string): TObject;
  626. begin
  627. Result:=GetObjectProp(Instance,PropName,Nil);
  628. end;
  629. Function GetObjectProp(Instance: TObject; const PropName: string; MinClass: TClass): TObject;
  630. begin
  631. Result:=GetObjectProp(Instance,FindPropInfo(Instance,PropName),MinClass);
  632. end;
  633. Function GetObjectProp(Instance: TObject; PropInfo : PPropInfo; MinClass: TClass): TObject;
  634. begin
  635. Result:=TObject(GetOrdProp(Instance,PropInfo));
  636. If (MinClass<>Nil) and (Result<>Nil) Then
  637. If Not Result.InheritsFrom(MinClass) then
  638. Result:=Nil;
  639. end;
  640. Procedure SetObjectProp(Instance: TObject; const PropName: string; Value: TObject);
  641. begin
  642. SetObjectProp(Instance,FindPropInfo(Instance,PropName),Value);
  643. end;
  644. Procedure SetObjectProp(Instance: TObject; PropInfo : PPropInfo; Value: TObject);
  645. begin
  646. SetOrdProp(Instance,PropInfo,Integer(Value));
  647. end;
  648. Function GetObjectPropClass(Instance: TObject; const PropName: string): TClass;
  649. begin
  650. Result:=GetTypeData(FindPropInfo(Instance,PropName)^.PropType)^.ClassType;
  651. end;
  652. { ---------------------------------------------------------------------
  653. String properties
  654. ---------------------------------------------------------------------}
  655. Function GetStrProp(Instance: TObject; PropInfo: PPropInfo): AnsiString;
  656. var
  657. Index, IValue: LongInt;
  658. ShortResult: ShortString;
  659. begin
  660. SetIndexValues(PropInfo, Index, IValue);
  661. case Propinfo^.PropType^.Kind of
  662. tkSString:
  663. case (PropInfo^.PropProcs) and 3 of
  664. ptField:
  665. Result := PShortString(Pointer(Instance) + LongWord(PropInfo^.GetProc))^;
  666. ptStatic:
  667. begin
  668. CallSStringFunc(Instance, PropInfo^.GetProc, Index, IValue, ShortResult);
  669. Result := ShortResult;
  670. end;
  671. ptVirtual:
  672. begin
  673. CallSStringFunc(Instance, PPointer(Pointer(Instance.ClassType) +
  674. LongWord(PropInfo^.GetProc))^, Index, IValue, ShortResult);
  675. Result := ShortResult;
  676. end;
  677. end;
  678. tkAString:
  679. case (PropInfo^.PropProcs) and 3 of
  680. ptField:
  681. Result := PAnsiString(Pointer(Instance) + LongWord(PropInfo^.GetProc))^;
  682. ptStatic:
  683. Pointer(Result) := Pointer(LongWord(CallIntegerFunc(Instance, PropInfo^.GetProc, Index, IValue)));
  684. ptVirtual:
  685. Pointer(Result) := Pointer(LongWord(CallIntegerFunc(Instance,
  686. PPointer(Pointer(Instance.ClassType) + LongWord(PropInfo^.GetProc))^, Index, IValue)));
  687. end;
  688. else
  689. // Property is neither of type AnsiString nor of type ShortString
  690. SetLength(Result, 0);
  691. end;
  692. end;
  693. Procedure SetAStrProp(Instance : TObject;PropInfo : PPropInfo;
  694. const Value : AnsiString);
  695. {
  696. Dirty trick based on fact that AnsiString is just a pointer,
  697. hence can be treated like an integer type.
  698. }
  699. var
  700. Index,Ivalue : Longint;
  701. begin
  702. SetIndexValues(PropInfo,Index,IValue);
  703. case (PropInfo^.PropProcs shr 2) and 3 of
  704. ptfield:
  705. PAnsiString(Pointer(Instance) + Longint(PropInfo^.SetProc))^ := Value;
  706. ptstatic:
  707. CallIntegerProc(Instance,PropInfo^.SetProc,Longint(Pointer(Value)),Index,IValue);
  708. ptvirtual:
  709. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Longint(Pointer(Value)),Index,IValue);
  710. end;
  711. end;
  712. Procedure SetSStrProp(Instance : TObject;PropInfo : PPropInfo;
  713. const Value : ShortString);
  714. Var Index,IValue: longint;
  715. begin
  716. SetIndexValues(PRopInfo,Index,IValue);
  717. case (PropInfo^.PropProcs shr 2) and 3 of
  718. ptfield:
  719. PShortString(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  720. ptstatic:
  721. CallSStringProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  722. ptvirtual:
  723. CallSStringProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  724. end;
  725. end;
  726. Procedure SetStrProp(Instance : TObject;PropInfo : PPropInfo;
  727. const Value : AnsiString);
  728. begin
  729. Case Propinfo^.PropType^.Kind of
  730. tkSString : SetSStrProp(Instance,PropInfo,Value);
  731. tkAString : SetAStrProp(Instance,Propinfo,Value);
  732. end;
  733. end;
  734. Function GetStrProp(Instance: TObject; const PropName: string): string;
  735. begin
  736. Result:=GetStrProp(Instance,FindPropInfo(Instance,PropName));
  737. end;
  738. Procedure SetStrProp(Instance: TObject; const PropName: string; const Value: AnsiString);
  739. begin
  740. SetStrProp(Instance,FindPropInfo(Instance,PropName),Value);
  741. end;
  742. { ---------------------------------------------------------------------
  743. Float properties
  744. ---------------------------------------------------------------------}
  745. Function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  746. var
  747. Index,Ivalue : longint;
  748. Value : Extended;
  749. begin
  750. SetIndexValues(PropInfo,Index,Ivalue);
  751. case (PropInfo^.PropProcs) and 3 of
  752. ptField:
  753. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  754. ftSingle:
  755. Value:=PSingle(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  756. ftDouble:
  757. Value:=PDouble(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  758. ftExtended:
  759. Value:=PExtended(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  760. {$ifndef m68k}
  761. ftcomp:
  762. Value:=PComp(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  763. {$endif m68k}
  764. end;
  765. ptStatic:
  766. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  767. ftSingle:
  768. Value:=CallSingleFunc(Instance,PropInfo^.GetProc,Index,IValue);
  769. ftDouble:
  770. Value:=CallDoubleFunc(Instance,PropInfo^.GetProc,Index,IValue);
  771. ftExtended:
  772. Value:=CallExtendedFunc(Instance,PropInfo^.GetProc,Index,IValue);
  773. end;
  774. ptVirtual:
  775. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  776. ftSingle:
  777. Value:=CallSingleFunc(Instance,
  778. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,
  779. Index,IValue);
  780. ftDouble:
  781. Value:=CallDoubleFunc(Instance,
  782. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,
  783. Index,IValue);
  784. ftExtended:
  785. Value:=CallExtendedFunc(Instance,
  786. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,
  787. Index,IValue);
  788. end;
  789. end;
  790. Result:=Value;
  791. end;
  792. Procedure SetFloatProp(Instance : TObject;PropInfo : PPropInfo;
  793. Value : Extended);
  794. type
  795. TSetExtendedProc = procedure(const AValue: Extended) of object;
  796. TSetExtendedProcIndex = procedure(Index: integer; const AValue: Extended) of object;
  797. TSetDoubleProc = procedure(const AValue: Double) of object;
  798. TSetDoubleProcIndex = procedure(Index: integer; const AValue: Double) of object;
  799. TSetSingleProc = procedure(const AValue: Single) of object;
  800. TSetSingleProcIndex = procedure(Index: integer; const AValue: Single) of object;
  801. Var IValue,Index : longint;
  802. AMethod: TMethod;
  803. begin
  804. SetIndexValues(PropInfo,Index,Ivalue);
  805. case (PropInfo^.PropProcs shr 2) and 3 of
  806. ptfield:
  807. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  808. ftSingle:
  809. PSingle(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  810. ftDouble:
  811. PDouble(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  812. ftExtended:
  813. PExtended(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  814. {$ifndef m68k}
  815. ftcomp:
  816. PComp(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Comp(Value);
  817. {$endif m68k}
  818. { Uncommenting this code results in a internal error!!
  819. ftFixed16:
  820. PFixed16(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  821. ftfixed32:
  822. PFixed32(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  823. }
  824. end;
  825. ptStatic, ptVirtual:
  826. begin
  827. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  828. AMethod.Code:=PropInfo^.SetProc
  829. else
  830. AMethod.Code:=
  831. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^;
  832. AMethod.Data:=Instance;
  833. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  834. ftSingle:
  835. if Index=0 then
  836. TSetSingleProc(AMethod)(Value)
  837. else
  838. TSetSingleProcIndex(AMethod)(IValue,Value);
  839. ftDouble:
  840. if Index=0 then
  841. TSetDoubleProc(AMethod)(Value)
  842. else
  843. TSetDoubleProcIndex(AMethod)(IValue,Value);
  844. ftExtended:
  845. if Index=0 then
  846. TSetExtendedProc(AMethod)(Value)
  847. else
  848. TSetExtendedProcIndex(AMethod)(IValue,Value);
  849. end;
  850. end;
  851. end;
  852. end;
  853. Function GetFloatProp(Instance: TObject; const PropName: string): Extended;
  854. begin
  855. Result:=GetFloatProp(Instance,FindPropInfo(Instance,PropName))
  856. end;
  857. Procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Extended);
  858. begin
  859. SetFloatProp(Instance,FindPropInfo(Instance,PropName),Value);
  860. end;
  861. { ---------------------------------------------------------------------
  862. Variant properties
  863. ---------------------------------------------------------------------}
  864. Function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
  865. begin
  866. {!!!!!!!!!!!}
  867. Result:=nil;
  868. end;
  869. Procedure SetVariantProp(Instance : TObject;PropInfo : PPropInfo;
  870. const Value: Variant);
  871. begin
  872. {!!!!!!!!!!!}
  873. end;
  874. Function GetVariantProp(Instance: TObject; const PropName: string): Variant;
  875. begin
  876. Result:=GetVariantProp(Instance,FindPropInfo(Instance,PropName));
  877. end;
  878. Procedure SetVariantProp(Instance: TObject; const PropName: string; const Value: Variant);
  879. begin
  880. SetVariantprop(instance,FindpropInfo(Instance,PropName),Value);
  881. end;
  882. { ---------------------------------------------------------------------
  883. Method properties
  884. ---------------------------------------------------------------------}
  885. Function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  886. var
  887. value: PMethod;
  888. Index,Ivalue : longint;
  889. begin
  890. SetIndexValues(PropInfo,Index,Ivalue);
  891. case (PropInfo^.PropProcs) and 3 of
  892. ptfield:
  893. Value:=PMethod(Pointer(Instance)+Longint(PropInfo^.GetProc));
  894. ptstatic:
  895. Value:=PMethod(LongInt(CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue)));
  896. ptvirtual:
  897. Value:=PMethod(LongInt(CallIntegerFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue)));
  898. end;
  899. GetMethodProp:=Value^;
  900. end;
  901. Procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo;
  902. const Value : TMethod);
  903. var
  904. Index,IValue : Longint;
  905. begin
  906. SetIndexValues(PropInfo,Index,Ivalue);
  907. case (PropInfo^.PropProcs shr 2) and 3 of
  908. ptfield:
  909. PMethod(Pointer(Instance)+Longint(PropInfo^.SetProc))^ := Value;
  910. ptstatic:
  911. CallIntegerProc(Instance,PropInfo^.SetProc,Integer(@Value), Index, IValue);
  912. ptvirtual:
  913. CallIntegerProc(Instance,
  914. PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,
  915. Integer(@Value), Index, IValue);
  916. end;
  917. end;
  918. Function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
  919. begin
  920. Result:=GetMethodProp(Instance,FindPropInfo(Instance,PropName));
  921. end;
  922. Procedure SetMethodProp(Instance: TObject; const PropName: string; const Value: TMethod);
  923. begin
  924. SetMethodProp(Instance,FindPropInfo(Instance,PropName),Value);
  925. end;
  926. { ---------------------------------------------------------------------
  927. Int64 properties
  928. ---------------------------------------------------------------------}
  929. Function GetInt64Prop(Instance: TObject; PropInfo: PPropInfo): Int64;
  930. var
  931. Index, IValue: LongInt;
  932. begin
  933. SetIndexValues(PropInfo,Index,Ivalue);
  934. case PropInfo^.PropProcs and 3 of
  935. ptfield:
  936. Result := PInt64(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  937. ptstatic:
  938. Result := CallIntegerFunc(Instance, PropInfo^.GetProc, Index, IValue);
  939. ptvirtual:
  940. Result := CallIntegerFunc(Instance,
  941. PPointer(Pointer(Instance.ClassType) + LongInt(PropInfo^.GetProc))^,
  942. Index, IValue);
  943. end;
  944. end;
  945. procedure SetInt64Prop(Instance: TObject; PropInfo: PPropInfo; const Value: Int64);
  946. var
  947. Index, IValue: LongInt;
  948. begin
  949. SetIndexValues(PropInfo,Index,Ivalue);
  950. case PropInfo^.PropProcs and 3 of
  951. ptfield:
  952. PInt64(Pointer(Instance)+Longint(PropInfo^.GetProc))^ := Value;
  953. ptstatic:
  954. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  955. ptvirtual:
  956. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  957. end;
  958. end;
  959. Function GetInt64Prop(Instance: TObject; const PropName: string): Int64;
  960. begin
  961. Result:=GetInt64Prop(Instance,FindPropInfo(Instance,PropName));
  962. end;
  963. Procedure SetInt64Prop(Instance: TObject; const PropName: string; const Value: Int64);
  964. begin
  965. SetInt64Prop(Instance,FindPropInfo(Instance,PropName),Value);
  966. end;
  967. { ---------------------------------------------------------------------
  968. All properties through variant.
  969. ---------------------------------------------------------------------}
  970. Function GetPropValue(Instance: TObject; const PropName: string): Variant;
  971. begin
  972. Result:=GetPropValue(Instance,PropName,True);
  973. end;
  974. Function GetPropValue(Instance: TObject; const PropName: string; PreferStrings: Boolean): Variant;
  975. begin
  976. end;
  977. Procedure SetPropValue(Instance: TObject; const PropName: string; const Value: Variant);
  978. begin
  979. end;
  980. { ---------------------------------------------------------------------
  981. Easy access methods that appeared in Delphi 5
  982. ---------------------------------------------------------------------}
  983. Function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
  984. begin
  985. Result:=GetPropInfo(Instance,PropName)<>Nil;
  986. end;
  987. Function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;
  988. begin
  989. Result:=GetPropInfo(AClass,PropName)<>Nil;
  990. end;
  991. Function PropIsType(Instance: TObject; const PropName: string; TypeKind: TTypeKind): Boolean;
  992. begin
  993. Result:=FindPropInfo(Instance,PropName)^.PropType^.Kind=TypeKind
  994. end;
  995. Function PropIsType(AClass: TClass; const PropName: string; TypeKind: TTypeKind): Boolean;
  996. begin
  997. Result:=PropType(AClass,PropName)=TypeKind
  998. end;
  999. Function PropType(Instance: TObject; const PropName: string): TTypeKind;
  1000. begin
  1001. Result:=FindPropInfo(Instance,PropName)^.PropType^.Kind;
  1002. end;
  1003. Function PropType(AClass: TClass; const PropName: string): TTypeKind;
  1004. begin
  1005. Result:=FindPropInfo(AClass,PropName)^.PropType^.Kind;
  1006. end;
  1007. Function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
  1008. begin
  1009. Result:=IsStoredProp(instance,FindPropInfo(Instance,PropName));
  1010. end;
  1011. end.
  1012. {
  1013. $Log$
  1014. Revision 1.16 2003-04-24 11:46:25 florian
  1015. * fixed wrong newlines
  1016. Revision 1.15 2003/03/29 16:55:56 michael
  1017. + Patch from Mattias Gaertner for single typeinfo
  1018. Revision 1.14 2002/09/07 16:01:22 peter
  1019. * old logs removed and tabs fixed
  1020. Revision 1.13 2002/04/04 18:32:59 peter
  1021. * merged getpropinfo fix
  1022. }