typinfo.pp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1998 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. {$ifndef AUTOOBJPAS}
  18. uses
  19. objpas;
  20. {$endif}
  21. // temporary types:
  22. type
  23. PShortString =^ShortString;
  24. PByte =^Byte;
  25. PLongint =^Longint;
  26. PBoolean =^Boolean;
  27. PSingle =^Single;
  28. PDouble =^Double;
  29. PExtended =^Extended;
  30. PComp =^Comp;
  31. PFixed16 =^Fixed16;
  32. { Doesn't exist ?
  33. PFIxed32 = ^Fixed32;
  34. }
  35. Variant = Pointer;
  36. TMethod = Pointer;
  37. {$MINENUMSIZE 1 this saves a lot of memory }
  38. // if you change one of the following enumeration types
  39. // you have also to change the compiler in an appropriate way !
  40. TTypeKind = (tkUnknown,tkInteger,tkChar,tkEnumeration,
  41. tkFloat,tkSet,tkMethod,tkSString,tkLString,tkAString,
  42. tkWString,tkVariant,tkArray,tkRecord,tkInterface,
  43. tkClass,tkObject,tkWChar,tkBool);
  44. TTOrdType = (otSByte,otUByte,otSWord,otUWord,otSLong,otULong);
  45. TFloatType = (ftSingle,ftDouble,ftExtended,ftComp,ftCurr,
  46. ftFixed16,ftFixed32);
  47. TMethodKind = (mkProcedure,mkFunction,mkSafeProcedure,mkSafeFunction);
  48. TParamFlags = set of (pfVar,pfConst,pfArray,pfAddress,pfReference,pfOut);
  49. TIntfFlags = set of (ifHasGuid,ifDispInterface,ifDispatch);
  50. {$MINENUMSIZE DEFAULT}
  51. const
  52. ptField = 0;
  53. ptStatic = 1;
  54. ptVirtual = 2;
  55. ptConst = 3;
  56. tkString = tkSString;
  57. type
  58. TTypeKinds = set of TTypeKind;
  59. {$PACKRECORDS 1}
  60. TTypeInfo = record
  61. Kind : TTypeKind;
  62. Name : ShortString;
  63. // here the type data follows as TTypeData record
  64. end;
  65. PTypeInfo = ^TTypeInfo;
  66. PPTypeInfo = ^PTypeInfo;
  67. PTypeData = ^TTypeData;
  68. TTypeData = packed record
  69. case TTypeKind of
  70. tkUnKnown,tkLString,tkWString,tkAString,tkVariant:
  71. ();
  72. tkInteger,tkChar,tkEnumeration,tkWChar:
  73. (OrdType : TTOrdType;
  74. case TTypeKind of
  75. tkInteger,tkChar,tkEnumeration,tkBool,tkWChar : (
  76. MinValue,MaxValue : Longint;
  77. case TTypeKind of
  78. tkEnumeration:
  79. (
  80. BaseType : PTypeInfo;
  81. NameList : ShortString)
  82. );
  83. tkSet:
  84. (CompType : PTypeInfo)
  85. );
  86. tkFloat:
  87. (FloatType : TFloatType);
  88. tkSString:
  89. (MaxLength : Byte);
  90. tkClass:
  91. (ClassType : TClass;
  92. ParentInfo : PTypeInfo;
  93. PropCount : SmallInt;
  94. UnitName : ShortString
  95. // here the properties follow as array of TPropInfo
  96. );
  97. tkMethod:
  98. ({!!!!!!!}
  99. );
  100. tkInterface:
  101. ({!!!!!!!}
  102. );
  103. end;
  104. // unsed, just for completeness
  105. TPropData = packed record
  106. PropCount : Word;
  107. PropList : record end;
  108. end;
  109. PPropInfo = ^TPropInfo;
  110. TPropInfo = packed record
  111. PropType : PTypeInfo;
  112. GetProc : Pointer;
  113. SetProc : Pointer;
  114. StoredProc : Pointer;
  115. Index : Integer;
  116. Default : Longint;
  117. NameIndex : SmallInt;
  118. // contains the type of the Get/Set/Storedproc, see also ptxxx
  119. // bit 0..1 GetProc
  120. // 2..3 SetProc
  121. // 4..5 StoredProc
  122. // 6 : true, constant index property
  123. PropProcs : Byte;
  124. Name : ShortString;
  125. end;
  126. TProcInfoProc = procedure(PropInfo : PPropInfo) of object;
  127. PPropList = ^TPropList;
  128. TPropList = array[0..65535] of PPropInfo;
  129. const
  130. tkAny = [Low(TTypeKind)..High(TTypeKind)];
  131. tkMethods = [tkMethod];
  132. tkProperties = tkAny-tkMethods-[tkUnknown];
  133. { general property handling }
  134. // just skips the id and the name
  135. function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
  136. // searches in the property PropName
  137. function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string) : PPropInfo;
  138. procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
  139. function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds;
  140. PropList : PPropList) : Integer;
  141. // returns true, if PropInfo is a stored property
  142. function IsStoredProp(Instance : TObject;PropInfo : PPropInfo) : Boolean;
  143. { subroutines to read/write properties }
  144. function GetOrdProp(Instance : TObject;PropInfo : PPropInfo) : Longint;
  145. procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;
  146. Value : Longint);
  147. function GetStrProp(Instance : TObject;PropInfo : PPropInfo) : Ansistring;
  148. procedure SetStrProp(Instance : TObject;PropInfo : PPropInfo;
  149. const Value : Ansistring);
  150. function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  151. procedure SetFloatProp(Instance : TObject;PropInfo : PPropInfo;
  152. Value : Extended);
  153. function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
  154. procedure SetVariantProp(Instance : TObject;PropInfo : PPropInfo;
  155. const Value: Variant);
  156. function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  157. procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo;
  158. const Value : TMethod);
  159. { misc. stuff }
  160. function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
  161. function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
  162. implementation
  163. {$ASMMODE ATT}
  164. function CallIntegerFunc(s : Pointer;Address : Pointer; INdex,IValue : Longint) : Integer;assembler;
  165. Label LINoPush;
  166. asm
  167. movl S,%esi
  168. movl Address,%edi
  169. // ? Indexed function
  170. movl Index,%eax
  171. xorl %eax,%eax
  172. jnz LINoPush
  173. movl IValue,%eax
  174. pushl %eax
  175. LINoPush:
  176. call (%edi)
  177. // now the result should be in EAX, untested yet (FK)
  178. end;
  179. function CallIntegerProc(s : Pointer;Address : Pointer;Value : Integer; INdex,IVAlue : Longint) : Integer;assembler;
  180. label LIPNoPush;
  181. asm
  182. movl S,%esi
  183. movl Address,%edi
  184. // Push value to set
  185. movl Value,%eax
  186. pushl %eax
  187. // ? Indexed procedure
  188. movl Index,%eax
  189. xorl %eax,%eax
  190. jnz LIPNoPush
  191. movl IValue,%eax
  192. pushl %eax
  193. LIPNoPush:
  194. call (%edi)
  195. // now the result should be in EAX, untested yet (FK)
  196. end;
  197. function CallExtendedFunc(s : Pointer;Address : Pointer; INdex,IValue : Longint) : Extended;assembler;
  198. Label LINoPush;
  199. asm
  200. movl S,%esi
  201. movl Address,%edi
  202. // ? Indexed function
  203. movl Index,%eax
  204. xorl %eax,%eax
  205. jnz LINoPush
  206. movl IValue,%eax
  207. pushl %eax
  208. LINoPush:
  209. call (%edi)
  210. //!! now What ??
  211. end;
  212. function CallExtendedProc(s : Pointer;Address : Pointer;Value : Extended; INdex,IVAlue : Longint) : Integer;assembler;
  213. label LIPNoPush;
  214. asm
  215. movl S,%esi
  216. movl Address,%edi
  217. // Push value to set
  218. //!! MUST BE CHANGED !!
  219. movl Value,%eax
  220. pushl %eax
  221. // ? Indexed procedure
  222. movl Index,%eax
  223. xorl %eax,%eax
  224. jnz LIPNoPush
  225. movl IValue,%eax
  226. pushl %eax
  227. LIPNoPush:
  228. call (%edi)
  229. end;
  230. function CallBooleanFunc(s : Pointer;Address : Pointer; Index,IValue : Longint) : Boolean;assembler;
  231. Label LBNoPush;
  232. asm
  233. movl S,%edi
  234. movl Address,%edi
  235. // ? Indexed function
  236. movl Index,%eax
  237. xorl %eax,%eax
  238. jnz LBNoPush
  239. movl IValue,%eax
  240. pushl %eax
  241. LBNoPush:
  242. call (%edi)
  243. // now the result should be in EAX, untested yet (FK)
  244. end;
  245. //!! Assembler functions can't have short stringreturn values.
  246. //!! So we make a procedure with var parameter.
  247. Procedure CallSStringFunc(s : Pointer;Address : Pointer; INdex,IValue : Longint;
  248. Var Res: Shortstring);assembler;
  249. Label LSSNoPush;
  250. asm
  251. movl S,%esi
  252. movl Address,%edi
  253. // ? Indexed function
  254. movl Index,%eax
  255. xorl %eax,%eax
  256. jnz LSSNoPush
  257. movl IValue,%eax
  258. pushl %eax
  259. LSSNoPush:
  260. call (%edi)
  261. //!! now what ?? MVC
  262. end;
  263. function CallSStringProc(s : Pointer;Address : Pointer;Value : ShortString; INdex,IVAlue : Longint);assembler;
  264. label LSSPNoPush;
  265. asm
  266. movl S,%esi
  267. movl Address,%edi
  268. // Push value to set
  269. //!! Is this correct for short strings ????
  270. movl Value,%eax
  271. pushl %eax
  272. // ? Indexed procedure
  273. movl Index,%eax
  274. xorl %eax,%eax
  275. jnz LSSPNoPush
  276. movl IValue,%eax
  277. pushl %eax
  278. LSSPNoPush:
  279. call (%edi)
  280. //!! now what ? MVC
  281. end;
  282. function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
  283. begin
  284. GetTypeData:=PTypeData(TypeInfo)+2+PByte(TypeInfo+1)^;
  285. end;
  286. function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string) : PPropInfo;
  287. var
  288. hp : PTypeData;
  289. i : longint;
  290. begin
  291. Result:=Nil;
  292. while Assigned(TypeInfo) do
  293. begin
  294. // skip the name
  295. hp:=GetTypeData(Typeinfo);
  296. // the class info rtti the property rtti follows
  297. // immediatly
  298. Result:=PPropInfo(@hp^.UnitName)+byte(hp^.UnitName[0])+1;
  299. for i:=1 to hp^.PropCount do
  300. begin
  301. // found a property of that name ?
  302. if Result^.Name=PropName then
  303. exit;
  304. // skip to next property
  305. Result:=PPropInfo(@Result^.Name)+byte(Result^.Name[0])+1;
  306. end;
  307. // parent class
  308. Typeinfo:=hp^.ParentInfo;
  309. end;
  310. end;
  311. function IsStoredProp(Instance : TObject;PropInfo : PPropInfo) : Boolean;
  312. begin
  313. case (PropInfo^.PropProcs shr 4) and 3 of
  314. ptfield:
  315. IsStoredProp:=PBoolean(Pointer(Instance)+Longint(PropInfo^.StoredProc))^;
  316. ptstatic:
  317. IsStoredProp:=CallBooleanFunc(Instance,PropInfo^.StoredProc,0,0);
  318. ptvirtual:
  319. IsStoredProp:=CallBooleanFunc(Instance,(PPointer(Instance.ClassType)+Longint(PropInfo^.StoredProc)),0,0);
  320. ptconst:
  321. IsStoredProp:=LongBool(PropInfo^.StoredProc);
  322. end;
  323. end;
  324. procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
  325. {
  326. Store Pointers to property information in the list pointed
  327. to by proplist. PRopList must contain enough space to hold ALL
  328. properties.
  329. }
  330. Type PWord = ^Word;
  331. Var TD : PTypeData;
  332. TP : PPropInfo;
  333. Count : Longint;
  334. begin
  335. TD:=GetTypeData(TypeInfo);
  336. // Get this objects TOTAL published properties count
  337. TP:=(@TD^.UnitName+Length(TD^.UnitName)+1);
  338. Count:=PWord(TP)^;
  339. // Now point TP to first propinfo record.
  340. Inc(Longint(TP),SizeOF(Word));
  341. While Count>0 do
  342. begin
  343. PropList^[0]:=TP;
  344. Inc(Longint(PropList),SizeOf(Pointer));
  345. // Point to TP next propinfo record.
  346. // Located at Name[Length(Name)+1] !
  347. TP:=PPropInfo((@TP^.Name)+PByte(@TP^.Name)^+1);
  348. Dec(Count);
  349. end;
  350. // recursive call for parent info.
  351. If TD^.Parentinfo<>Nil then
  352. GetPropInfos (TD^.ParentInfo,PropList);
  353. end;
  354. Procedure InsertProp (PL : PProplist;PI : PPropInfo; Count : longint);
  355. VAr I : Longint;
  356. begin
  357. I:=0;
  358. While (I<Count) and (PI^.Name>PL^[I]^.Name) do Inc(I);
  359. If I<Count then
  360. Move(PL^[I],PL[I+1],Count-I*SizeOf(Pointer));
  361. PL^[I]:=PI;
  362. end;
  363. function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds;
  364. PropList : PPropList) : Integer;
  365. {
  366. Store Pointers to property information OF A CERTAIN KIND in the list pointed
  367. to by proplist. PRopList must contain enough space to hold ALL
  368. properties.
  369. }
  370. Var TempList : PPropList;
  371. PropInfo : PPropinfo;
  372. I,Count : longint;
  373. begin
  374. Result:=0;
  375. Count:=GetTypeData(TypeInfo)^.Propcount;
  376. If Count>0 then
  377. begin
  378. GetMem(TempList,Count*SizeOf(Pointer));
  379. Try
  380. GetPropInfos(TypeInfo,TempList);
  381. For I:=0 to Count-1 do
  382. begin
  383. PropInfo:=TempList^[i];
  384. If PropInfo^.PropType^.Kind in TypeKinds then
  385. begin
  386. InsertProp(PropList,PropInfo,Result);
  387. Inc(Result);
  388. end;
  389. end;
  390. finally
  391. FreeMem(TempList,Count*SizeOf(Pointer));
  392. end;
  393. end;
  394. end;
  395. Procedure SetIndexValues (P: PPRopInfo; Var Index,IValue : Longint);
  396. begin
  397. Index:=((P^.PropProcs shr 6) and 1);
  398. If Index=0 then
  399. IValue:=P^.Index
  400. else
  401. IValue:=0;
  402. end;
  403. function GetOrdProp(Instance : TObject;PropInfo : PPropInfo) : Longint;
  404. var
  405. value,Index,Ivalue : longint;
  406. begin
  407. SetIndexValues(PropInfo,Index,Ivalue);
  408. case (PropInfo^.PropProcs) and 3 of
  409. ptfield:
  410. Value:=PLongint(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  411. ptstatic:
  412. Value:=CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue);
  413. ptvirtual:
  414. Value:=CallIntegerFunc(Instance,
  415. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  416. Index,IValue);
  417. end;
  418. { cut off unnecessary stuff }
  419. case GetTypeData(PropInfo^.PropType)^.OrdType of
  420. otSWord,otUWord:
  421. Value:=Value and $ffff;
  422. otSByte,otUByte:
  423. Value:=Value and $ff;
  424. end;
  425. GetOrdProp:=Value;
  426. end;
  427. procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;
  428. Value : Longint);
  429. Var Index,IValue : Longint;
  430. begin
  431. { cut off unnecessary stuff }
  432. case GetTypeData(PropInfo^.PropType)^.OrdType of
  433. otSWord,otUWord:
  434. Value:=Value and $ffff;
  435. otSByte,otUByte:
  436. Value:=Value and $ff;
  437. end;
  438. SetIndexValues(PropInfo,Index,Ivalue);
  439. case (PropInfo^.PropProcs) and 3 of
  440. ptfield:
  441. PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  442. ptstatic:
  443. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  444. ptvirtual:
  445. CallIntegerProc(Instance,
  446. (PPointer(Instance.ClassType)+Longint(PropInfo^.SetProc)),
  447. Value,Index,IValue);
  448. end;
  449. end;
  450. Function GetAStrProp(Instance : TObject;PropInfo : PPropInfo):Pointer;
  451. {
  452. Dirty trick based on fact that AnsiString is just a pointer,
  453. hence can be treated like an integer type.
  454. }
  455. var
  456. value : Pointer;
  457. Index,Ivalue : Longint;
  458. begin
  459. SetIndexValues(PropInfo,Index,IValue);
  460. case (PropInfo^.PropProcs) and 3 of
  461. ptfield:
  462. Value:=Pointer(PLongint(Pointer(Instance)+Longint(PropInfo^.GetProc))^);
  463. ptstatic:
  464. Value:=Pointer(CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue));
  465. ptvirtual:
  466. Value:=Pointer(CallIntegerFunc(Instance,
  467. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  468. Index,IValue));
  469. end;
  470. GetAstrProp:=Value;
  471. end;
  472. Function GetSStrProp(Instance : TObject;PropInfo : PPropInfo):ShortString;
  473. var
  474. value : ShortString;
  475. Index,IValue : Longint;
  476. begin
  477. SetIndexValues(PropInfo,Index,IValue);
  478. case (PropInfo^.PropProcs) and 3 of
  479. ptfield:
  480. Value:=PShortString(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  481. ptstatic:
  482. CallSStringFunc(Instance,PropInfo^.GetProc,Index,IValue,Value);
  483. ptvirtual:
  484. CallSSTringFunc(Instance,
  485. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  486. Index,Ivalue,Value);
  487. end;
  488. GetSStrProp:=Value;
  489. end;
  490. function GetStrProp(Instance : TObject;PropInfo : PPropInfo) : Ansistring;
  491. begin
  492. Case Propinfo^.PropType^.Kind of
  493. tkSString : Result:=GetSStrProp(Instance,PropInfo);
  494. tkAString : Pointer(Result):=GetAStrProp(Instance,Propinfo);
  495. else
  496. Result:='';
  497. end;
  498. end;
  499. procedure SetAStrProp(Instance : TObject;PropInfo : PPropInfo;
  500. const Value : AnsiString);
  501. {
  502. Dirty trick based on fact that AnsiString is just a pointer,
  503. hence can be treated like an integer type.
  504. }
  505. var
  506. Index,Ivalue : Longint;
  507. begin
  508. SetIndexValues(PropInfo,Index,IValue);
  509. case (PropInfo^.PropProcs) and 3 of
  510. ptfield:
  511. PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Longint(Pointer(Value)) ;
  512. ptstatic:
  513. CallIntegerProc(Instance,PropInfo^.SetProc,Longint(Pointer(Value)),Index,IValue);
  514. ptvirtual:
  515. CallIntegerProc(Instance,
  516. (PPointer(Instance.ClassType)+Longint(PropInfo^.SetProc)),
  517. Longint(Pointer(Value)),Index,IValue);
  518. end;
  519. end;
  520. procedure SetSStrProp(Instance : TObject;PropInfo : PPropInfo;
  521. const Value : ShortString);
  522. Var Index,IValue: longint;
  523. begin
  524. SetIndexValues(PRopInfo,Index,IValue);
  525. case (PropInfo^.PropProcs) and 3 of
  526. ptfield:
  527. PShortString(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  528. ptstatic:
  529. CallSStringProc(Instance,PropInfo^.GetProc,Value,Index,IValue);
  530. ptvirtual:
  531. CallSStringProc(Instance,
  532. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  533. Value,Index,IValue);
  534. end;
  535. end;
  536. procedure SetStrProp(Instance : TObject;PropInfo : PPropInfo;
  537. const Value : AnsiString);
  538. begin
  539. Case Propinfo^.PropType^.Kind of
  540. tkSString : SetSStrProp(Instance,PropInfo,Value);
  541. tkAString : SetAStrProp(Instance,Propinfo,Value);
  542. end;
  543. end;
  544. function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  545. var
  546. Index,Ivalue : longint;
  547. Value : Extended;
  548. begin
  549. SetIndexValues(PropInfo,Index,Ivalue);
  550. case (PropInfo^.PropProcs) and 3 of
  551. ptfield:
  552. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  553. ftSingle:
  554. Value:=PSingle(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  555. ftDouble:
  556. Value:=PDouble(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  557. ftExtended:
  558. Value:=PExtended(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  559. ftcomp:
  560. Value:=PComp(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  561. { Uncommenting this code results in a internal error!!
  562. ftFixed16:
  563. Value:=PFixed16(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  564. ftfixed32:
  565. Value:=PFixed32(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  566. }
  567. end;
  568. ptstatic:
  569. Value:=CallExtendedFunc(Instance,PropInfo^.GetProc,Index,IValue);
  570. ptvirtual:
  571. Value:=CallExtendedFunc(Instance,
  572. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  573. Index,IValue);
  574. end;
  575. end;
  576. procedure SetFloatProp(Instance : TObject;PropInfo : PPropInfo;
  577. Value : Extended);
  578. Var IValue,Index : longint;
  579. begin
  580. SetIndexValues(PropInfo,Index,Ivalue);
  581. case (PropInfo^.PropProcs) and 3 of
  582. ptfield:
  583. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  584. ftSingle:
  585. PSingle(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  586. ftDouble:
  587. PDouble(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  588. ftExtended:
  589. PExtended(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  590. ftcomp:
  591. PComp(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  592. { Uncommenting this code results in a internal error!!
  593. ftFixed16:
  594. PFixed16(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  595. ftfixed32:
  596. PFixed32(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  597. }
  598. end;
  599. ptstatic:
  600. CallExtendedProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  601. ptvirtual:
  602. CallExtendedProc(Instance,
  603. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  604. Value,Index,IValue);
  605. end;
  606. end;
  607. function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
  608. begin
  609. {!!!!!!!!!!!}
  610. end;
  611. procedure SetVariantProp(Instance : TObject;PropInfo : PPropInfo;
  612. const Value: Variant);
  613. begin
  614. {!!!!!!!!!!!}
  615. end;
  616. function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  617. begin
  618. {!!!!!!!!!!!!}
  619. end;
  620. procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo;
  621. const Value : TMethod);
  622. begin
  623. {!!!!!!!!!!!}
  624. end;
  625. function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
  626. Var PS : PShortString;
  627. PT : PTypeData;
  628. begin
  629. PT:=GetTypeData(GetTypeData(TypeInfo)^.BaseType);
  630. If PT^.MinValue<0 then Value:=Ord(Value<>0); {map to 0/1}
  631. PS:=@PT^.NameList;
  632. While Value>0 Do
  633. begin
  634. PS:=PS+PByte(PS)^+1;
  635. Dec(Value);
  636. end;
  637. Result:=PS^;
  638. end;
  639. function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
  640. Var PS : PShortString;
  641. PT : PTypeData;
  642. Count : longint;
  643. begin
  644. If Length(Name)=0 then exit(-1);
  645. PT:=GetTypeData(GetTypeData(TypeInfo)^.BaseType);
  646. Count:=0;
  647. Result:=-1;
  648. PS:=@PT^.NameList;
  649. While (Result=-1) and (PByte(PS)^<>0) do
  650. begin
  651. If PS^=Name then
  652. Result:=Count;
  653. PS:=PS+PByte(PS)^;
  654. Inc(Count);
  655. end;
  656. end;
  657. end.
  658. {
  659. $Log$
  660. Revision 1.16 1998-12-02 12:35:07 michael
  661. More changes for type-information
  662. Revision 1.15 1998/11/26 14:57:47 michael
  663. + Added packrecords 1
  664. Revision 1.11 1998/09/24 23:45:28 peter
  665. * updated for auto objpas loading
  666. Revision 1.10 1998/09/20 08:25:34 florian
  667. + description of tpropinfo.propprocs bit 6 added
  668. Revision 1.9 1998/09/19 15:25:45 florian
  669. * procedure GetOrdProp added
  670. Revision 1.8 1998/09/19 08:33:53 florian
  671. + some procedures added
  672. Revision 1.7 1998/09/08 09:52:31 florian
  673. * small problems fixed
  674. Revision 1.6 1998/09/08 00:08:36 michael
  675. Made it compilable
  676. Revision 1.5 1998/09/07 23:11:43 florian
  677. + more fields to TTypeInfo added
  678. Revision 1.4 1998/09/07 19:34:47 florian
  679. * constant value is now supported as stored condition
  680. Revision 1.3 1998/09/07 08:32:59 florian
  681. + procedure IsStoredProc added
  682. Revision 1.2 1998/09/06 21:27:05 florian
  683. + some methods and declarations added
  684. Revision 1.1 1998/08/25 22:30:00 florian
  685. + initial revision:
  686. o constants
  687. o basic type data record
  688. }