typinfo.pp 25 KB

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