typinfo.pp 41 KB

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