48
44
TFloatType = (ftSingle,ftDouble,ftExtended,ftComp,ftCurr);
49
45
TMethodKind = (mkProcedure,mkFunction,mkConstructor,mkDestructor,
50
46
mkClassProcedure, mkClassFunction);
51
TParamFlags = set of (pfVar,pfConst,pfArray,pfAddress,pfReference,pfOut);
52
TIntfFlag = (ifHasGuid,ifDispInterface,ifDispatch);
47
TParamFlag = (pfVar,pfConst,pfArray,pfAddress,pfReference,pfOut);
48
TParamFlags = set of TParamFlag;
49
TIntfFlag = (ifHasGuid,ifDispInterface,ifDispatch,ifHasStrGUID);
53
50
TIntfFlags = set of TIntfFlag;
54
51
TIntfFlagsBase = set of TIntfFlag;
128
125
(MinInt64Value, MaxInt64Value: Int64);
130
127
(MinQWordValue, MaxQWordValue: QWord);
130
IntfParent: PTypeInfo;
131
IntfFlags : TIntfFlagsBase;
133
IntfUnit: ShortString;
134
IntfParent: PPTypeInfo;
137
RawIntfParent: PTypeInfo;
138
RawIntfFlags : TIntfFlagsBase;
140
RawIntfUnit: ShortString;
136
141
IIDStr: ShortString;
137
IntfUnit: ShortString;
191
195
Function FindPropInfo(Instance: TObject; const PropName: string): PPropInfo;
192
196
Function FindPropInfo(AClass:TClass;const PropName: string): PPropInfo;
193
197
Procedure GetPropInfos(TypeInfo : PTypeInfo;PropList : PPropList);
195
Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds; PropList : PPropList;Sorted : boolean):longint;
196
Function GetPropList(TypeInfo: PTypeInfo; var PropList: PPropList): SizeInt;
198
Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds; PropList : PPropList;Sorted : boolean = true):longint;
198
Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds; PropList : PPropList;Sorted : boolean = true):longint;
199
199
Function GetPropList(TypeInfo: PTypeInfo; out PropList: PPropList): SizeInt;
200
function GetPropList(AObject: TObject; out PropList: PPropList): Integer;
203
204
// Property information routines.
232
233
Procedure SetStrProp(Instance: TObject; const PropName: string; const Value: AnsiString);
233
234
Procedure SetStrProp(Instance: TObject; PropInfo : PPropInfo; const Value : Ansistring);
235
{$ifdef HASWIDESTRING}
236
236
Function GetWideStrProp(Instance: TObject; PropInfo: PPropInfo): WideString;
237
237
Function GetWideStrProp(Instance: TObject; const PropName: string): WideString;
238
238
Procedure SetWideStrProp(Instance: TObject; const PropName: string; const Value: WideString);
239
239
Procedure SetWideStrProp(Instance: TObject; PropInfo: PPropInfo; const Value: WideString);
240
{$endif HASWIDESTRING}
242
241
Function GetFloatProp(Instance: TObject; PropInfo : PPropInfo) : Extended;
243
242
Function GetFloatProp(Instance: TObject; const PropName: string): Extended;
275
274
// Auxiliary routines, which may be useful
276
275
Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
277
276
Function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
277
function GetEnumNameCount(enum1: PTypeInfo): SizeInt;
279
function SetToString(TypeInfo: PTypeInfo; Value: Integer; Brackets: Boolean) : String;
278
280
function SetToString(PropInfo: PPropInfo; Value: Integer; Brackets: Boolean) : String;
279
281
function SetToString(PropInfo: PPropInfo; Value: Integer) : String;
280
282
function StringToSet(PropInfo: PPropInfo; const Value: string): Integer;
283
function StringToSet(TypeInfo: PTypeInfo; const Value: string): Integer;
283
286
BooleanIdents: array[Boolean] of String = ('False', 'True');
287
290
EPropertyError = Class(Exception);
288
291
TGetPropValue = Function (Instance: TObject; const PropName: string; PreferStrings: Boolean) : Variant;
289
292
TSetPropValue = Procedure (Instance: TObject; const PropName: string; const Value: Variant);
290
TGetVariantProp = Function (Instance: TObject; PropInfo : PPropInfo): Variant;
293
TGetVariantProp = Function (Instance: TObject; PropInfo : PPropInfo): Variant;
291
294
TSetVariantProp = Procedure (Instance: TObject; PropInfo : PPropInfo; const Value: Variant);
294
297
OnGetPropValue : TGetPropValue = Nil;
295
298
OnSetPropValue : TSetPropValue = Nil;
296
299
OnGetVariantprop : TGetVariantProp = Nil;
297
300
OnSetVariantprop : TSetVariantProp = Nil;
304
307
PMethod = ^TMethod;
308
311
---------------------------------------------------------------------}
310
313
function aligntoptr(p : pointer) : pointer;
312
315
{$ifdef FPC_REQUIRES_PROPER_ALIGNMENT}
313
if (ptrint(p) mod sizeof(ptrint))<>0 then
314
inc(ptrint(p),sizeof(ptrint)-ptrint(p) mod sizeof(ptrint));
316
if (ptruint(p) and (sizeof(ptruint)-1))<>0 then
317
ptruint(p) := (ptruint(p) + sizeof(ptruint) - 1) and not (sizeof(ptruint) - 1);
315
318
{$endif FPC_REQUIRES_PROPER_ALIGNMENT}
320
323
Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
365
function GetEnumNameCount(enum1: PTypeInfo): SizeInt;
371
PT:=GetTypeData(enum1);
376
While (PByte(PS)^<>0) do
378
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
362
386
Function SetToString(PropInfo: PPropInfo; Value: Integer; Brackets: Boolean) : String;
389
Result:=SetToString(PropInfo^.PropType,Value,Brackets);
392
Function SetToString(TypeInfo: PTypeInfo; Value: Integer; Brackets: Boolean) : String;
369
PTI:=GetTypeData(PropInfo^.PropType)^.CompType;
399
PTI:=GetTypeData(TypeInfo)^.CompType;
371
401
For I:=0 to SizeOf(Integer)*8-1 do
605
// Get this objects TOTAL published properties count
570
606
TD:=GetTypeData(TypeInfo);
571
// Get this objects TOTAL published properties count
572
TP:=aligntoptr(PPropInfo(aligntoptr((@TD^.UnitName+Length(TD^.UnitName)+1))));
574
// Now point TP to first propinfo record.
575
Inc(Pointer(TP),SizeOF(Word));
580
Inc(Pointer(PropList),SizeOf(Pointer));
581
// Point to TP next propinfo record.
582
// Located at Name[Length(Name)+1] !
583
TP:=aligntoptr(PPropInfo(pointer(@TP^.Name)+PByte(@TP^.Name)^+1));
586
// recursive call for parent info.
587
If TD^.Parentinfo<>Nil then
588
GetPropInfos (TD^.ParentInfo,PropList);
608
FillChar(PropList^,TD^.PropCount*sizeof(Pointer),0);
610
TD:=GetTypeData(TypeInfo);
611
// published properties count for this object
612
TP:=aligntoptr(PPropInfo(aligntoptr((@TD^.UnitName+Length(TD^.UnitName)+1))));
614
// Now point TP to first propinfo record.
615
Inc(Pointer(TP),SizeOF(Word));
619
// Don't overwrite properties with the same name
620
if PropList^[TP^.NameIndex]=nil then
621
PropList^[TP^.NameIndex]:=TP;
622
// Point to TP next propinfo record.
623
// Located at Name[Length(Name)+1] !
624
TP:=aligntoptr(PPropInfo(pointer(@TP^.Name)+PByte(@TP^.Name)^+1));
627
TypeInfo:=TD^.Parentinfo;
591
631
Procedure InsertProp (PL : PProplist;PI : PPropInfo; Count : longint);
610
650
//Const InsertProps : array[false..boolean] of TInsertProp = (InsertPropNoSort,InsertProp);
613
Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds; PropList : PPropList;Sorted : boolean):longint;
615
652
Function GetPropList(TypeInfo : PTypeInfo;TypeKinds : TTypeKinds; PropList : PPropList;Sorted : boolean = true):longint;
619
655
Store Pointers to property information OF A CERTAIN KIND in the list pointed
659
Function GetPropList(TypeInfo: PTypeInfo; var PropList: PPropList): SizeInt;
661
694
Function GetPropList(TypeInfo: PTypeInfo; out PropList: PPropList): SizeInt;
664
result:=GetTypeData(TypeInfo)^.Propcount;
667
getmem(PropList,result*sizeof(pointer));
668
GetPropInfos(TypeInfo,PropList);
696
result:=GetTypeData(TypeInfo)^.Propcount;
699
getmem(PropList,result*sizeof(pointer));
700
GetPropInfos(TypeInfo,PropList);
705
function GetPropList(AObject: TObject; out PropList: PPropList): Integer;
707
Result := GetPropList(PTypeInfo(AObject.ClassInfo), PropList);
673
710
{ ---------------------------------------------------------------------
674
711
Property access functions
787
828
DataSize: Integer;
788
829
AMethod : TMethod;
790
if PropInfo^.PropType^.Kind in [tkInt64,tkQword] then
831
if PropInfo^.PropType^.Kind in [tkInt64,tkQword
832
{ why do we have to handle classes here, see also below? (FK) }
794
if PropInfo^.PropType^.Kind <> tkClass then
840
if not(PropInfo^.PropType^.Kind in [tkInt64,tkQword,tkClass]) then
796
842
{ cut off unnecessary stuff }
797
843
case GetTypeData(PropInfo^.PropType)^.OrdType of
813
859
1: PByte(Pointer(Instance)+Ptrint(PropInfo^.SetProc))^:=Byte(Value);
814
860
2: PWord(Pointer(Instance)+Ptrint(PropInfo^.SetProc))^:=Word(Value);
815
4:PLongint(Pointer(Instance)+Ptrint(PropInfo^.SetProc))^:=Longint(Value);
861
4: PLongint(Pointer(Instance)+Ptrint(PropInfo^.SetProc))^:=Longint(Value);
816
862
8: PInt64(Pointer(Instance)+Ptrint(PropInfo^.SetProc))^:=Value;
1233
1273
TGetDoubleProcIndex = function(Index: integer): Double of object;
1234
1274
TGetSingleProc = function:Single of object;
1235
1275
TGetSingleProcIndex = function(Index: integer):Single of object;
1236
{$ifdef HASCURRENCY}
1237
1276
TGetCurrencyProc = function : Currency of object;
1238
1277
TGetCurrencyProcIndex = function(Index: integer) : Currency of object;
1239
{$endif HASCURRENCY}
1241
1279
AMethod : TMethod;
1281
1317
Result:=TGetExtendedProc(AMethod)()
1283
1319
Result:=TGetExtendedProcIndex(AMethod)(PropInfo^.Index);
1284
{$ifdef HASCURRENCY}
1286
1321
if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
1287
1322
Result:=TGetCurrencyProc(AMethod)()
1289
1324
Result:=TGetCurrencyProcIndex(AMethod)(PropInfo^.Index);
1290
{$endif HASCURRENCY}
1302
1336
TSetDoubleProcIndex = procedure(Index: integer; const AValue: Double) of object;
1303
1337
TSetSingleProc = procedure(const AValue: Single) of object;
1304
1338
TSetSingleProcIndex = procedure(Index: integer; const AValue: Single) of object;
1305
{$ifdef HASCURRENCY}
1306
1339
TSetCurrencyProc = procedure(const AValue: Currency) of object;
1307
1340
TSetCurrencyProcIndex = procedure(Index: integer; const AValue: Currency) of object;
1308
{$endif HASCURRENCY}
1310
1342
AMethod : TMethod;
1354
1384
TSetExtendedProc(AMethod)(Value)
1356
1386
TSetExtendedProcIndex(AMethod)(PropInfo^.Index,Value);
1357
{$ifdef HASCURRENCY}
1359
1388
if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
1360
1389
TSetCurrencyProc(AMethod)(Value)
1362
1391
TSetCurrencyProcIndex(AMethod)(PropInfo^.Index,Value);
1363
{$endif HASCURRENCY}
1563
$Log: typinfo.pp,v $
1564
Revision 1.45 2005/04/16 09:24:29 michael
1565
+ Moved constants to rtlconsts and added callbacks for variant support
1567
Revision 1.44 2005/04/14 17:43:07 michael
1568
+ Added getPropValue by Uberto Barbini
1570
Revision 1.43 2005/04/05 06:44:25 marco
1571
* Currency property patch from Dean Zobec
1573
Revision 1.42 2005/04/03 11:50:58 marco
1574
* patch for 3854 added. There are probably more places that need explicit
1577
Revision 1.41 2005/03/14 21:15:52 florian
1578
* fixed compilation on i386
1580
Revision 1.40 2005/03/14 19:16:06 peter
1581
* getordprop supports int64
1583
Revision 1.39 2005/02/26 20:59:38 florian
1584
* fixed 1.0.10 issue
1586
Revision 1.38 2005/02/26 11:37:01 florian
1587
+ overload of GetPropList added
1589
Revision 1.37 2005/02/22 12:14:56 marco
1590
* getproplist sorted param added.
1592
Revision 1.36 2005/02/14 17:13:31 peter
1595
Revision 1.35 2005/02/08 16:10:29 florian
1596
* TTOrdType -> TOrdType