typinfo.pp 26 KB

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