typinfo.pp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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(pointer(TypeInfo)+2+PByte(pointer(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(pointer(@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(pointer(@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(Pointer(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(pointer(@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,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue);
  423. end;
  424. { cut off unnecessary stuff }
  425. case GetTypeData(PropInfo^.PropType)^.OrdType of
  426. otSWord,otUWord:
  427. Value:=Value and $ffff;
  428. otSByte,otUByte:
  429. Value:=Value and $ff;
  430. end;
  431. GetOrdProp:=Value;
  432. end;
  433. procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;
  434. Value : Longint);
  435. var
  436. Index,IValue : Longint;
  437. DataSize: Integer;
  438. begin
  439. { cut off unnecessary stuff }
  440. case GetTypeData(PropInfo^.PropType)^.OrdType of
  441. otSWord,otUWord: begin
  442. Value:=Value and $ffff;
  443. DataSize := 2;
  444. end;
  445. otSByte,otUByte: begin
  446. Value:=Value and $ff;
  447. DataSize := 1;
  448. end;
  449. else DataSize := 4;
  450. end;
  451. SetIndexValues(PropInfo,Index,Ivalue);
  452. case (PropInfo^.PropProcs shr 2) and 3 of
  453. ptfield:
  454. case DataSize of
  455. 1: PByte(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Byte(Value);
  456. 2: PWord(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Word(Value);
  457. 4: PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  458. end;
  459. ptstatic:
  460. CallIntegerProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  461. ptvirtual:
  462. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Value,Index,IValue);
  463. end;
  464. end;
  465. Function GetAStrProp(Instance : TObject;PropInfo : PPropInfo):Pointer;
  466. {
  467. Dirty trick based on fact that AnsiString is just a pointer,
  468. hence can be treated like an integer type.
  469. }
  470. var
  471. value : Pointer;
  472. Index,Ivalue : Longint;
  473. begin
  474. SetIndexValues(PropInfo,Index,IValue);
  475. case (PropInfo^.PropProcs) and 3 of
  476. ptfield:
  477. Value:=Pointer(PLongint(Pointer(Instance)+Longint(PropInfo^.GetProc))^);
  478. ptstatic:
  479. Value:=Pointer(CallIntegerFunc(Instance,PropInfo^.GetProc,Index,IValue));
  480. ptvirtual:
  481. Value:=Pointer(CallIntegerFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue));
  482. end;
  483. GetAstrProp:=Value;
  484. end;
  485. Function GetSStrProp(Instance : TObject;PropInfo : PPropInfo):ShortString;
  486. var
  487. value : ShortString;
  488. Index,IValue : Longint;
  489. begin
  490. SetIndexValues(PropInfo,Index,IValue);
  491. case (PropInfo^.PropProcs) and 3 of
  492. ptfield:
  493. Value:=PShortString(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  494. ptstatic:
  495. CallSStringFunc(Instance,PropInfo^.GetProc,Index,IValue,Value);
  496. ptvirtual:
  497. CallSSTringFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,Ivalue,Value);
  498. end;
  499. GetSStrProp:=Value;
  500. end;
  501. function GetStrProp(Instance : TObject;PropInfo : PPropInfo) : Ansistring;
  502. begin
  503. Case Propinfo^.PropType^.Kind of
  504. tkSString : Result:=GetSStrProp(Instance,PropInfo);
  505. tkAString : Pointer(Result):=GetAStrProp(Instance,Propinfo);
  506. else
  507. Result:='';
  508. end;
  509. end;
  510. procedure SetAStrProp(Instance : TObject;PropInfo : PPropInfo;
  511. const Value : AnsiString);
  512. {
  513. Dirty trick based on fact that AnsiString is just a pointer,
  514. hence can be treated like an integer type.
  515. }
  516. var
  517. Index,Ivalue : Longint;
  518. begin
  519. SetIndexValues(PropInfo,Index,IValue);
  520. case (PropInfo^.PropProcs shr 2) and 3 of
  521. ptfield:
  522. PLongint(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Longint(Pointer(Value)) ;
  523. ptstatic:
  524. CallIntegerProc(Instance,PropInfo^.SetProc,Longint(Pointer(Value)),Index,IValue);
  525. ptvirtual:
  526. CallIntegerProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.SetProc))^,Longint(Pointer(Value)),Index,IValue);
  527. end;
  528. end;
  529. procedure SetSStrProp(Instance : TObject;PropInfo : PPropInfo;
  530. const Value : ShortString);
  531. Var Index,IValue: longint;
  532. begin
  533. SetIndexValues(PRopInfo,Index,IValue);
  534. case (PropInfo^.PropProcs shr 2) and 3 of
  535. ptfield:
  536. PShortString(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  537. ptstatic:
  538. CallSStringProc(Instance,PropInfo^.GetProc,Value,Index,IValue);
  539. ptvirtual:
  540. CallSStringProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Value,Index,IValue);
  541. end;
  542. end;
  543. procedure SetStrProp(Instance : TObject;PropInfo : PPropInfo;
  544. const Value : AnsiString);
  545. begin
  546. Case Propinfo^.PropType^.Kind of
  547. tkSString : SetSStrProp(Instance,PropInfo,Value);
  548. tkAString : SetAStrProp(Instance,Propinfo,Value);
  549. end;
  550. end;
  551. function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  552. var
  553. Index,Ivalue : longint;
  554. Value : Extended;
  555. begin
  556. SetIndexValues(PropInfo,Index,Ivalue);
  557. case (PropInfo^.PropProcs) and 3 of
  558. ptfield:
  559. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  560. ftSingle:
  561. Value:=PSingle(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  562. ftDouble:
  563. Value:=PDouble(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  564. ftExtended:
  565. Value:=PExtended(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  566. ftcomp:
  567. Value:=PComp(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  568. { Uncommenting this code results in a internal error!!
  569. ftFixed16:
  570. Value:=PFixed16(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  571. ftfixed32:
  572. Value:=PFixed32(Pointer(Instance)+Longint(PropInfo^.GetProc))^;
  573. }
  574. end;
  575. ptstatic:
  576. Value:=CallExtendedFunc(Instance,PropInfo^.GetProc,Index,IValue);
  577. ptvirtual:
  578. Value:=CallExtendedFunc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Index,IValue);
  579. end;
  580. Result:=Value;
  581. end;
  582. procedure SetFloatProp(Instance : TObject;PropInfo : PPropInfo;
  583. Value : Extended);
  584. Var IValue,Index : longint;
  585. begin
  586. SetIndexValues(PropInfo,Index,Ivalue);
  587. case (PropInfo^.PropProcs shr 2) and 3 of
  588. ptfield:
  589. Case GetTypeData(PropInfo^.PropType)^.FloatType of
  590. ftSingle:
  591. PSingle(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  592. ftDouble:
  593. PDouble(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  594. ftExtended:
  595. PExtended(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  596. ftcomp:
  597. PComp(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Comp(Value);
  598. { Uncommenting this code results in a internal error!!
  599. ftFixed16:
  600. PFixed16(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  601. ftfixed32:
  602. PFixed32(Pointer(Instance)+Longint(PropInfo^.SetProc))^:=Value;
  603. }
  604. end;
  605. ptstatic:
  606. CallExtendedProc(Instance,PropInfo^.SetProc,Value,Index,IValue);
  607. ptvirtual:
  608. CallExtendedProc(Instance,PPointer(Pointer(Instance.ClassType)+Longint(PropInfo^.GetProc))^,Value,Index,IValue);
  609. end;
  610. end;
  611. function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
  612. begin
  613. {!!!!!!!!!!!}
  614. Result:=nil;
  615. end;
  616. procedure SetVariantProp(Instance : TObject;PropInfo : PPropInfo;
  617. const Value: Variant);
  618. begin
  619. {!!!!!!!!!!!}
  620. end;
  621. function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  622. begin
  623. {!!!!!!!!!!!!}
  624. Result:=nil;
  625. end;
  626. procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo;
  627. const Value : TMethod);
  628. begin
  629. {!!!!!!!!!!!}
  630. end;
  631. function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
  632. Var PS : PShortString;
  633. PT : PTypeData;
  634. begin
  635. PT:=GetTypeData(TypeInfo);
  636. // ^.BaseType);
  637. // If PT^.MinValue<0 then Value:=Ord(Value<>0); {map to 0/1}
  638. PS:=@PT^.NameList;
  639. While Value>0 Do
  640. begin
  641. PS:=PShortString(pointer(PS)+PByte(PS)^+1);
  642. Dec(Value);
  643. end;
  644. Result:=PS^;
  645. end;
  646. function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
  647. Var PS : PShortString;
  648. PT : PTypeData;
  649. Count : longint;
  650. begin
  651. If Length(Name)=0 then exit(-1);
  652. PT:=GetTypeData(TypeInfo);
  653. Count:=0;
  654. Result:=-1;
  655. PS:=@PT^.NameList;
  656. While (Result=-1) and (PByte(PS)^<>0) do
  657. begin
  658. If PS^=Name then
  659. Result:=Count;
  660. PS:=PShortString(pointer(PS)+PByte(PS)^);
  661. Inc(Count);
  662. end;
  663. end;
  664. end.
  665. {
  666. $Log$
  667. Revision 1.27 1999-09-08 16:14:43 peter
  668. * pointer fixes
  669. Revision 1.26 1999/09/03 15:39:23 michael
  670. * Fixes from Sebastian Guenther
  671. Revision 1.25 1999/08/29 22:21:27 michael
  672. * Patch from Sebastian Guenther
  673. Revision 1.24 1999/08/06 13:21:40 michael
  674. * Patch from Sebastian Guenther
  675. Revision 1.23 1999/06/04 12:48:37 michael
  676. * Fix by Sebastian Guenther.
  677. Revision 1.22 1999/05/19 12:03:23 florian
  678. * the set/get procedures must be called with call %edi instead call (%edi)
  679. * handling of extended and string properties fixed
  680. Revision 1.21 1999/05/07 11:02:14 florian
  681. * two typos fixed
  682. Revision 1.20 1999/05/03 07:30:07 michael
  683. * Fixes in getenum*
  684. Revision 1.19 1999/04/08 11:31:04 peter
  685. * removed warnings
  686. Revision 1.18 1999/01/19 16:08:12 pierre
  687. ?? is callSStringProc a function ??
  688. Revision 1.17 1998/12/15 22:43:13 peter
  689. * removed temp symbols
  690. Revision 1.16 1998/12/02 12:35:07 michael
  691. More changes for type-information
  692. Revision 1.15 1998/11/26 14:57:47 michael
  693. + Added packrecords 1
  694. Revision 1.11 1998/09/24 23:45:28 peter
  695. * updated for auto objpas loading
  696. Revision 1.10 1998/09/20 08:25:34 florian
  697. + description of tpropinfo.propprocs bit 6 added
  698. Revision 1.9 1998/09/19 15:25:45 florian
  699. * procedure GetOrdProp added
  700. Revision 1.8 1998/09/19 08:33:53 florian
  701. + some procedures added
  702. Revision 1.7 1998/09/08 09:52:31 florian
  703. * small problems fixed
  704. Revision 1.6 1998/09/08 00:08:36 michael
  705. Made it compilable
  706. Revision 1.5 1998/09/07 23:11:43 florian
  707. + more fields to TTypeInfo added
  708. Revision 1.4 1998/09/07 19:34:47 florian
  709. * constant value is now supported as stored condition
  710. Revision 1.3 1998/09/07 08:32:59 florian
  711. + procedure IsStoredProc added
  712. Revision 1.2 1998/09/06 21:27:05 florian
  713. + some methods and declarations added
  714. Revision 1.1 1998/08/25 22:30:00 florian
  715. + initial revision:
  716. o constants
  717. o basic type data record
  718. }