typinfo.pp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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. asm
  162. movl S,%esi
  163. movl Address,%edi
  164. // ? Indexed function
  165. movl Index,%eax
  166. xorl %eax,%eax
  167. jnz .LINoPush
  168. movl IValue,%eax
  169. pushl %eax
  170. .LINoPush:
  171. call (%edi)
  172. // now the result should be in EAX, untested yet (FK)
  173. end;
  174. function CallIntegerProc(s : Pointer;Address : Pointer;Value : Integer; INdex,IVAlue : Longint) : Integer;assembler;
  175. asm
  176. movl S,%esi
  177. movl Address,%edi
  178. // Push value to set
  179. movl Value,%eax
  180. pushl %eax
  181. // ? Indexed procedure
  182. movl Index,%eax
  183. xorl %eax,%eax
  184. jnz .LIPNoPush
  185. movl IValue,%eax
  186. pushl %eax
  187. .LIPNoPush:
  188. call (%edi)
  189. // now the result should be in EAX, untested yet (FK)
  190. end;
  191. function CallExtendedFunc(s : Pointer;Address : Pointer; INdex,IValue : Longint) : Extended;assembler;
  192. asm
  193. movl S,%esi
  194. movl Address,%edi
  195. // ? Indexed function
  196. movl Index,%eax
  197. xorl %eax,%eax
  198. jnz .LINoPush
  199. movl IValue,%eax
  200. pushl %eax
  201. .LINoPush:
  202. call (%edi)
  203. //!! now What ??
  204. end;
  205. function CallExtendedProc(s : Pointer;Address : Pointer;Value : Extended; INdex,IVAlue : Longint) : Integer;assembler;
  206. asm
  207. movl S,%esi
  208. movl Address,%edi
  209. // Push value to set
  210. //!! MUST BE CHANGED !!
  211. movl Value,%eax
  212. pushl %eax
  213. // ? Indexed procedure
  214. movl Index,%eax
  215. xorl %eax,%eax
  216. jnz .LIPNoPush
  217. movl IValue,%eax
  218. pushl %eax
  219. .LIPNoPush:
  220. call (%edi)
  221. end;
  222. function CallBooleanFunc(s : Pointer;Address : Pointer; Index,IValue : Longint) : Boolean;assembler;
  223. asm
  224. movl S,%edi
  225. movl Address,%edi
  226. // ? Indexed function
  227. movl Index,%eax
  228. xorl %eax,%eax
  229. jnz .LBNoPush
  230. movl IValue,%eax
  231. pushl %eax
  232. .LBNoPush:
  233. call (%edi)
  234. // now the result should be in EAX, untested yet (FK)
  235. end;
  236. //!! Assembler functions can't have short stringreturn values.
  237. //!! So we make a procedure with var parameter.
  238. Procedure CallSStringFunc(s : Pointer;Address : Pointer; INdex,IValue : Longint;
  239. Var Res: Shortstring);assembler;
  240. asm
  241. movl S,%esi
  242. movl Address,%edi
  243. // ? Indexed function
  244. movl Index,%eax
  245. xorl %eax,%eax
  246. jnz .LSSNoPush
  247. movl IValue,%eax
  248. pushl %eax
  249. .LSSNoPush:
  250. call (%edi)
  251. //!! now what ?? MVC
  252. end;
  253. Procedure CallSStringProc(s : Pointer;Address : Pointer;Value : ShortString; INdex,IVAlue : Longint);assembler;
  254. asm
  255. movl S,%esi
  256. movl Address,%edi
  257. // Push value to set
  258. //!! Is this correct for short strings ????
  259. movl Value,%eax
  260. pushl %eax
  261. // ? Indexed procedure
  262. movl Index,%eax
  263. xorl %eax,%eax
  264. jnz .LSSPNoPush
  265. movl IValue,%eax
  266. pushl %eax
  267. .LSSPNoPush:
  268. call (%edi)
  269. //!! now what ? MVC
  270. end;
  271. function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
  272. begin
  273. GetTypeData:=PTypeData(TypeInfo)+2+PByte(TypeInfo+1)^;
  274. end;
  275. function GetPropInfo(TypeInfo : PTypeInfo;const PropName : string) : PPropInfo;
  276. var
  277. hp : PTypeData;
  278. i : longint;
  279. begin
  280. Result:=Nil;
  281. while Assigned(TypeInfo) do
  282. begin
  283. // skip the name
  284. hp:=GetTypeData(Typeinfo);
  285. // the class info rtti the property rtti follows
  286. // immediatly
  287. Result:=PPropInfo(@hp^.UnitName)+byte(hp^.UnitName[0])+1;
  288. for i:=1 to hp^.PropCount do
  289. begin
  290. // found a property of that name ?
  291. if Result^.Name=PropName then
  292. exit;
  293. // skip to next property
  294. Result:=PPropInfo(@Result^.Name)+byte(Result^.Name[0])+1;
  295. end;
  296. // parent class
  297. Typeinfo:=hp^.ParentInfo;
  298. end;
  299. end;
  300. function IsStoredProp(Instance : TObject;PropInfo : PPropInfo) : Boolean;
  301. begin
  302. case (PropInfo^.PropProcs shr 4) and 3 of
  303. ptfield:
  304. IsStoredProp:=PBoolean(Pointer(Instance)+Longint(PropInfo^.StoredProc))^;
  305. ptstatic:
  306. IsStoredProp:=CallBooleanFunc(Instance,PropInfo^.StoredProc,0,0);
  307. ptvirtual:
  308. IsStoredProp:=CallBooleanFunc(Instance,(PPointer(Instance.ClassType)+Longint(PropInfo^.StoredProc)),0,0);
  309. ptconst:
  310. IsStoredProp:=LongBool(PropInfo^.StoredProc);
  311. end;
  312. end;
  313. procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
  314. {
  315. Store Pointers to property information in the list pointed
  316. to by proplist. PRopList must contain enough space to hold ALL
  317. properties.
  318. }
  319. Type PWord = ^Word;
  320. Var TD : PTypeData;
  321. TP : PPropInfo;
  322. Count : Longint;
  323. begin
  324. TD:=GetTypeData(TypeInfo);
  325. // Get this objects TOTAL published properties count
  326. TP:=(@TD^.UnitName+Length(TD^.UnitName)+1);
  327. Count:=PWord(TP)^;
  328. // Now point TP to first propinfo record.
  329. Inc(Longint(TP),SizeOF(Word));
  330. While Count>0 do
  331. begin
  332. PropList^[0]:=TP;
  333. Inc(Longint(PropList),SizeOf(Pointer));
  334. // Point to TP next propinfo record.
  335. // Located at Name[Length(Name)+1] !
  336. TP:=PPropInfo((@TP^.Name)+PByte(@TP^.Name)^+1);
  337. Dec(Count);
  338. end;
  339. // recursive call for parent info.
  340. If TD^.Parentinfo<>Nil then
  341. GetPropInfos (TD^.ParentInfo,PropList);
  342. end;
  343. Procedure InsertProp (PL : PProplist;PI : PPropInfo; Count : longint);
  344. VAr I : Longint;
  345. begin
  346. I:=0;
  347. While (I<Count) and (PI^.Name>PL^[I]^.Name) do Inc(I);
  348. If I<Count then
  349. Move(PL^[I],PL[I+1],Count-I*SizeOf(Pointer));
  350. PL^[I]:=PI;
  351. end;
  352. function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds;
  353. PropList : PPropList) : Integer;
  354. {
  355. Store Pointers to property information OF A CERTAIN KIND in the list pointed
  356. to by proplist. PRopList must contain enough space to hold ALL
  357. properties.
  358. }
  359. Var TempList : PPropList;
  360. PropInfo : PPropinfo;
  361. I,Count : longint;
  362. begin
  363. Result:=0;
  364. Count:=GetTypeData(TypeInfo)^.Propcount;
  365. If Count>0 then
  366. begin
  367. GetMem(TempList,Count*SizeOf(Pointer));
  368. Try
  369. GetPropInfos(TypeInfo,TempList);
  370. For I:=0 to Count-1 do
  371. begin
  372. PropInfo:=TempList^[i];
  373. If PropInfo^.PropType^.Kind in TypeKinds then
  374. begin
  375. InsertProp(PropList,PropInfo,Result);
  376. Inc(Result);
  377. end;
  378. end;
  379. finally
  380. FreeMem(TempList,Count*SizeOf(Pointer));
  381. end;
  382. end;
  383. end;
  384. Procedure SetIndexValues (P: PPRopInfo; Var Index,IValue : Longint);
  385. begin
  386. Index:=((P^.PropProcs shr 6) and 1);
  387. If Index=0 then
  388. IValue:=P^.Index
  389. else
  390. IValue:=0;
  391. end;
  392. function GetOrdProp(Instance : TObject;PropInfo : PPropInfo) : Longint;
  393. var
  394. value,Index,Ivalue : longint;
  395. begin
  396. SetIndexValues(PropInfo,Index,Ivalue);
  397. case (PropInfo^.PropProcs) and 3 of
  398. ptfield:
  399. Value:=PLongint(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  400. ptstatic:
  401. Value:=CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue);
  402. ptvirtual:
  403. Value:=CallIntegerFunc(Instance,
  404. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  405. Index,IValue);
  406. end;
  407. { cut off unnecessary stuff }
  408. case GetTypeData(PropInfo^.PropType)^.OrdType of
  409. otSWord,otUWord:
  410. Value:=Value and $ffff;
  411. otSByte,otUByte:
  412. Value:=Value and $ff;
  413. end;
  414. GetOrdProp:=Value;
  415. end;
  416. procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;
  417. Value : Longint);
  418. Var Index,IValue : Longint;
  419. begin
  420. { cut off unnecessary stuff }
  421. case GetTypeData(PropInfo^.PropType)^.OrdType of
  422. otSWord,otUWord:
  423. Value:=Value and $ffff;
  424. otSByte,otUByte:
  425. Value:=Value and $ff;
  426. end;
  427. SetIndexValues(PropInfo,Index,Ivalue);
  428. case (PropInfo^.PropProcs) and 3 of
  429. ptfield:
  430. PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  431. ptstatic:
  432. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  433. ptvirtual:
  434. CallIntegerProc(Instance,
  435. (PPointer(Instance.ClassType)+Longint(PropInfo^.SetProc)),
  436. Value,Index,IValue);
  437. end;
  438. end;
  439. Function GetAStrProp(Instance : TObject;PropInfo : PPropInfo):Pointer;
  440. {
  441. Dirty trick based on fact that AnsiString is just a pointer,
  442. hence can be treated like an integer type.
  443. }
  444. var
  445. value : Pointer;
  446. Index,Ivalue : Longint;
  447. begin
  448. SetIndexValues(PropInfo,Index,IValue);
  449. case (PropInfo^.PropProcs) and 3 of
  450. ptfield:
  451. Value:=Pointer(PLongint(Pointer(Instance)+Longint(PropInfo^.GetProc))^);
  452. ptstatic:
  453. Value:=Pointer(CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue));
  454. ptvirtual:
  455. Value:=Pointer(CallIntegerFunc(Instance,
  456. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  457. Index,IValue));
  458. end;
  459. GetAstrProp:=Value;
  460. end;
  461. Function GetSStrProp(Instance : TObject;PropInfo : PPropInfo):ShortString;
  462. var
  463. value : ShortString;
  464. Index,IValue : Longint;
  465. begin
  466. SetIndexValues(PropInfo,Index,IValue);
  467. case (PropInfo^.PropProcs) and 3 of
  468. ptfield:
  469. Value:=PShortString(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  470. ptstatic:
  471. CallSStringFunc(Instance,PropInfo^.GetProc,Index,IValue,Value);
  472. ptvirtual:
  473. CallSSTringFunc(Instance,
  474. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  475. Index,Ivalue,Value);
  476. end;
  477. GetSStrProp:=Value;
  478. end;
  479. function GetStrProp(Instance : TObject;PropInfo : PPropInfo) : Ansistring;
  480. begin
  481. Case Propinfo^.PropType^.Kind of
  482. tkSString : Result:=GetSStrProp(Instance,PropInfo);
  483. tkAString : Pointer(Result):=GetAStrProp(Instance,Propinfo);
  484. else
  485. Result:='';
  486. end;
  487. end;
  488. procedure SetAStrProp(Instance : TObject;PropInfo : PPropInfo;
  489. const Value : AnsiString);
  490. {
  491. Dirty trick based on fact that AnsiString is just a pointer,
  492. hence can be treated like an integer type.
  493. }
  494. var
  495. Index,Ivalue : Longint;
  496. begin
  497. SetIndexValues(PropInfo,Index,IValue);
  498. case (PropInfo^.PropProcs) and 3 of
  499. ptfield:
  500. PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Longint(Pointer(Value)) ;
  501. ptstatic:
  502. CallIntegerProc(Instance,PropInfo^.SetProc,Longint(Pointer(Value)),Index,IValue);
  503. ptvirtual:
  504. CallIntegerProc(Instance,
  505. (PPointer(Instance.ClassType)+Longint(PropInfo^.SetProc)),
  506. Longint(Pointer(Value)),Index,IValue);
  507. end;
  508. end;
  509. procedure SetSStrProp(Instance : TObject;PropInfo : PPropInfo;
  510. const Value : ShortString);
  511. Var Index,IValue: longint;
  512. begin
  513. SetIndexValues(PRopInfo,Index,IValue);
  514. case (PropInfo^.PropProcs) and 3 of
  515. ptfield:
  516. PShortString(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  517. ptstatic:
  518. CallSStringProc(Instance,PropInfo^.GetProc,Value,Index,IValue);
  519. ptvirtual:
  520. CallSStringProc(Instance,
  521. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  522. Value,Index,IValue);
  523. end;
  524. end;
  525. procedure SetStrProp(Instance : TObject;PropInfo : PPropInfo;
  526. const Value : AnsiString);
  527. begin
  528. Case Propinfo^.PropType^.Kind of
  529. tkSString : SetSStrProp(Instance,PropInfo,Value);
  530. tkAString : SetAStrProp(Instance,Propinfo,Value);
  531. end;
  532. end;
  533. function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  534. var
  535. Index,Ivalue : longint;
  536. Value : Extended;
  537. begin
  538. SetIndexValues(PropInfo,Index,Ivalue);
  539. case (PropInfo^.PropProcs) and 3 of
  540. ptfield:
  541. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  542. ftSingle:
  543. Value:=PSingle(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  544. ftDouble:
  545. Value:=PDouble(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  546. ftExtended:
  547. Value:=PExtended(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  548. ftcomp:
  549. Value:=PComp(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  550. { Uncommenting this code results in a internal error!!
  551. ftFixed16:
  552. Value:=PFixed16(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  553. ftfixed32:
  554. Value:=PFixed32(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  555. }
  556. end;
  557. ptstatic:
  558. Value:=CallExtendedFunc(Instance,PropInfo^.GetProc,Index,IValue);
  559. ptvirtual:
  560. Value:=CallExtendedFunc(Instance,
  561. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  562. Index,IValue);
  563. end;
  564. Result:=Value;
  565. end;
  566. procedure SetFloatProp(Instance : TObject;PropInfo : PPropInfo;
  567. Value : Extended);
  568. Var IValue,Index : longint;
  569. begin
  570. SetIndexValues(PropInfo,Index,Ivalue);
  571. case (PropInfo^.PropProcs) and 3 of
  572. ptfield:
  573. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  574. ftSingle:
  575. PSingle(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  576. ftDouble:
  577. PDouble(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  578. ftExtended:
  579. PExtended(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  580. ftcomp:
  581. PComp(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Comp(Value);
  582. { Uncommenting this code results in a internal error!!
  583. ftFixed16:
  584. PFixed16(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  585. ftfixed32:
  586. PFixed32(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  587. }
  588. end;
  589. ptstatic:
  590. CallExtendedProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  591. ptvirtual:
  592. CallExtendedProc(Instance,
  593. (PPointer(Instance.ClassType)+Longint(PropInfo^.GetProc)),
  594. Value,Index,IValue);
  595. end;
  596. end;
  597. function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
  598. begin
  599. {!!!!!!!!!!!}
  600. Result:=nil;
  601. end;
  602. procedure SetVariantProp(Instance : TObject;PropInfo : PPropInfo;
  603. const Value: Variant);
  604. begin
  605. {!!!!!!!!!!!}
  606. end;
  607. function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  608. begin
  609. {!!!!!!!!!!!!}
  610. Result:=nil;
  611. end;
  612. procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo;
  613. const Value : TMethod);
  614. begin
  615. {!!!!!!!!!!!}
  616. end;
  617. function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
  618. Var PS : PShortString;
  619. PT : PTypeData;
  620. begin
  621. PT:=GetTypeData(GetTypeData(TypeInfo)^.BaseType);
  622. If PT^.MinValue<0 then Value:=Ord(Value<>0); {map to 0/1}
  623. PS:=@PT^.NameList;
  624. While Value>0 Do
  625. begin
  626. PS:=PS+PByte(PS)^+1;
  627. Dec(Value);
  628. end;
  629. Result:=PS^;
  630. end;
  631. function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
  632. Var PS : PShortString;
  633. PT : PTypeData;
  634. Count : longint;
  635. begin
  636. If Length(Name)=0 then exit(-1);
  637. PT:=GetTypeData(GetTypeData(TypeInfo)^.BaseType);
  638. Count:=0;
  639. Result:=-1;
  640. PS:=@PT^.NameList;
  641. While (Result=-1) and (PByte(PS)^<>0) do
  642. begin
  643. If PS^=Name then
  644. Result:=Count;
  645. PS:=PS+PByte(PS)^;
  646. Inc(Count);
  647. end;
  648. end;
  649. end.
  650. {
  651. $Log$
  652. Revision 1.19 1999-04-08 11:31:04 peter
  653. * removed warnings
  654. Revision 1.18 1999/01/19 16:08:12 pierre
  655. ?? is callSStringProc a function ??
  656. Revision 1.17 1998/12/15 22:43:13 peter
  657. * removed temp symbols
  658. Revision 1.16 1998/12/02 12:35:07 michael
  659. More changes for type-information
  660. Revision 1.15 1998/11/26 14:57:47 michael
  661. + Added packrecords 1
  662. Revision 1.11 1998/09/24 23:45:28 peter
  663. * updated for auto objpas loading
  664. Revision 1.10 1998/09/20 08:25:34 florian
  665. + description of tpropinfo.propprocs bit 6 added
  666. Revision 1.9 1998/09/19 15:25:45 florian
  667. * procedure GetOrdProp added
  668. Revision 1.8 1998/09/19 08:33:53 florian
  669. + some procedures added
  670. Revision 1.7 1998/09/08 09:52:31 florian
  671. * small problems fixed
  672. Revision 1.6 1998/09/08 00:08:36 michael
  673. Made it compilable
  674. Revision 1.5 1998/09/07 23:11:43 florian
  675. + more fields to TTypeInfo added
  676. Revision 1.4 1998/09/07 19:34:47 florian
  677. * constant value is now supported as stored condition
  678. Revision 1.3 1998/09/07 08:32:59 florian
  679. + procedure IsStoredProc added
  680. Revision 1.2 1998/09/06 21:27:05 florian
  681. + some methods and declarations added
  682. Revision 1.1 1998/08/25 22:30:00 florian
  683. + initial revision:
  684. o constants
  685. o basic type data record
  686. }