typinfo.pp 25 KB

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