[prev] [prev-tail] [tail] [up]

### 23.3 Functions and Procedures

#### FindPropInfo

Declaration:
  Function FindPropInfo(AClass:TClass;const PropName: string): PPropInfo;
  Function FindPropInfo(Instance: TObject; const PropName: string): PPropInfo;
Description:
  FindPropInfo examines the published property information of a class and returns a pointer to the property information for property PropName. The class to be examined can be specified in one of two ways:
  AClass
    a class pointer.
  Instance
    an instance of the class to be investigated.

  If the property does not exist, a EPropertyError exception will be raised. The GetPropInfo (844) function has the same function as the FindPropInfo function, but returns Nil if the property does not exist.

Errors:
  Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetPropInfo (844), GetPropList (846), GetPropInfos (845)

Listing: typinfex/ex14.pp

Program example13;
{ This program demonstrates the FindPropInfo function }
{$mode objfpc}
uses
rttiobj,typinfo,sysutils;
Var
O : TMyTestObject;
PT : PTypeData;
PI : PPropInfo;
I,J : Longint;
PP : PPropList;
prI : PPropInfo;
begin
O:=TMyTestObject.Create;
PI:=FindPropInfo(O,'BooleanField');
Writeln('FindPropInfo(Instance,BooleanField) : ',PI^.Name);
PI:=FindPropInfo(O.ClassType,'ByteField');
Writeln('FindPropInfo(Class,ByteField) : ',PI^.Name);
Write ('FindPropInfo(Class,NonExistingProp) : ');
Try
PI:=FindPropInfo(O,'NonExistingProp');
except
On E: Exception do
Writeln('Caught exception "',E.ClassName,'" with message : ',E.Message);
end;
O.Free;
end.

#### GetEnumName

Declaration:
  Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
Description:
  GetEnumName scans the type information for the enumeration type described by TypeInfo and returns the name of the enumeration constant for the element with ordinal value equal to Value.

  If Value is out of range, the first element of the enumeration type is returned. The result is lowercased, but this may change in the future.

  This can be used in combination with GetOrdProp to stream a property of an enumerated type.

Errors:
  No check is done to determine whether TypeInfo really points to the type information for an enumerated type.
See also:
  GetOrdProp (843), GetEnumValue (837)

Listing: typinfex/ex9.pp

program example9;
{ This program demonstrates the GetEnumName, GetEnumValue functions }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
TI : PTypeInfo;
begin
O:=TMyTestObject.Create;
TI:=GetPropInfo(O,'MyEnumField')^.PropType;
Writeln('GetEnumName : ',GetEnumName(TI,Ord(O.MyEnumField)));
Writeln('GetEnumValue(mefirst) : ',GetEnumName(TI,GetEnumValue(TI,'mefirst')));
O.Free;
end.

#### GetEnumProp

Declaration:
  Function GetEnumProp(Instance: TObject;const PropInfo: PPropInfo): string;
  Function GetEnumProp(Instance: TObject;const PropName: string): string;
Description:
  GetEnumProp returns the value of an property of an enumerated type and returns the name of the enumerated value for the objetc Instance. The property whose value must be returned can be specified by its property info in PropInfo or by its name in PropName
Errors:
  No check is done to determine whether PropInfo really points to the property information for an enumerated type. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  SetEnumProp (854) GetOrdProp (843), GetStrProp (849), GetInt64Prop (838),GetMethodProp (839), GetSetProp (848), GetObjectProp (842), GetEnumProp (836)

Listing: typinfex/ex2.pp

program example2;
{ This program demonstrates the GetEnumProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
TI : PTypeInfo;
begin
O:=TMyTestObject.Create;
PI:=GetPropInfo(O,'MyEnumField');
TI:=PI^.PropType;
Writeln('Enum property : ');
Writeln('Value : ',GetEnumName(TI,Ord(O.MyEnumField)));
Writeln('Get (name) : ',GetEnumProp(O,'MyEnumField'));
Writeln('Get (propinfo) : ',GetEnumProp(O,PI));
SetEnumProp(O,'MyEnumField','meFirst');
Writeln('Set (name,meFirst) : ',GetEnumName(TI,Ord(O.MyEnumField)));
SetEnumProp(O,PI,'meSecond');
Writeln('Set (propinfo,meSecond) : ',GetEnumName(TI,Ord(O.MyEnumField)));
O.Free;
end.

#### GetEnumValue

Declaration:
  Function GetEnumValue(TypeInfo : PTypeInfo;const Name : string) : Integer;
Description:
  GetEnumValue scans the type information for the enumeration type described by TypeInfor and returns the ordinal value for the element in the enumerated type that has identifier Name. The identifier is searched in a case-insensitive manner.

  This can be used to set the value of enumerated properties from a stream.

Errors:
  If Name is not found in the list of enumerated values, then -1 is returned. No check is done whether TypeInfo points to the type information for an enumerated type.
See also:
  GetEnumName (835), SetOrdProp (857)

For an example, see GetEnumName (835).

#### GetFloatProp

Declaration:
  Function GetFloatProp(Instance : TObject;PropInfo : PPropInfo) : Extended;
  Procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Extended);
Description:
  GetFloatProp returns the value of the float property described by PropInfo or with name Propname for the object Instance. All float types are converted to extended.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid float property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  SetFloatProp (855), GetOrdProp (843), GetStrProp (849), GetInt64Prop (838),GetMethodProp (839), GetSetProp (848), GetObjectProp (842), GetEnumProp (836)

Listing: typinfex/ex4.pp

program example4;
{ This program demonstrates the GetFloatProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
begin
O:=TMyTestObject.Create;
Writeln('Real property : ');
PI:=GetPropInfo(O,'RealField');
Writeln('Value : ',O.RealField);
Writeln('Get (name) : ',GetFloatProp(O,'RealField'));
Writeln('Get (propinfo) : ',GetFloatProp(O,PI));
SetFloatProp(O,'RealField',system.Pi);
Writeln('Set (name,pi) : ',O.RealField);
SetFloatProp(O,PI,exp(1));
Writeln('Set (propinfo,e) : ',O.RealField);
Writeln('Extended property : ');
PI:=GetPropInfo(O,'ExtendedField');
Writeln('Value : ',O.ExtendedField);
Writeln('Get (name) : ',GetFloatProp(O,'ExtendedField'));
Writeln('Get (propinfo) : ',GetFloatProp(O,PI));
SetFloatProp(O,'ExtendedField',system.Pi);
Writeln('Set (name,pi) : ',O.ExtendedField);
SetFloatProp(O,PI,exp(1));
Writeln('Set (propinfo,e) : ',O.ExtendedField);
O.Free;
end.

#### GetInt64Prop

Declaration:
  Function GetInt64Prop(Instance: TObject; PropInfo: PPropInfo): Int64;
  Function GetInt64Prop(Instance: TObject; const PropName: string): Int64;
Description:
  Publishing of Int64 properties is not yet supported by Free Pascal. This function is provided for Delphi compatibility only at the moment.

  GetInt64Prop returns the value of the property of type Int64 that is described by PropInfo or with name Propname for the object Instance.

Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid Int64 property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception
See also:
  SetInt64Prop (855), GetOrdProp (843), GetStrProp (849), GetFloatProp (837), GetMethodProp (839), GetSetProp (848), GetObjectProp (842), GetEnumProp (836)

Listing: typinfex/ex15.pp

program example15;
{ This program demonstrates the GetInt64Prop function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
begin
O:=TMyTestObject.Create;
Writeln('Int64 property : ');
PI:=GetPropInfo(O,'Int64Field');
Writeln('Value : ',O.Int64Field);
Writeln('Get (name) : ',GetInt64Prop(O,'Int64Field'));
Writeln('Get (propinfo) : ',GetInt64Prop(O,PI));
SetInt64Prop(O,'Int64Field',12345);
Writeln('Set (name,12345) : ',O.Int64Field);
SetInt64Prop(O,PI,54321);
Writeln('Set (propinfo,54321) : ',O.Int64Field);
O.Free;
end.

#### GetMethodProp

Declaration:
  Function GetMethodProp(Instance : TObject;PropInfo : PPropInfo) : TMethod;
  Function GetMethodProp(Instance: TObject; const PropName: string): TMethod;
Description:
  GetMethodProp returns the method the property described by PropInfo or with name Propname for object Instance. The return type TMethod is defined in the SysUtils unit as:

       TMethod = packed record
         Code, Data: Pointer;
       end;

  Data points to the instance of the class with the method Code.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid method property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception
See also:
  SetMethodProp (856), GetOrdProp (843), GetStrProp (849), GetFloatProp (837), GetInt64Prop (838), GetSetProp (848), GetObjectProp (842), GetEnumProp (836)

Listing: typinfex/ex6.pp

program example6;
{ This program demonstrates the GetMethodProp function }
{$mode objfpc}
uses rttiobj,typinfo,sysutils;
Type
TNotifyObject = Class(TObject)
Procedure Notification1(Sender : TObject);
Procedure Notification2(Sender : TObject);
end;
Procedure TNotifyObject.Notification1(Sender : TObject);
begin
Write('Received notification 1 of object with class: ');
Writeln(Sender.ClassName);
end;
Procedure TNotifyObject.Notification2(Sender : TObject);
begin
Write('Received notification 2 of object with class: ');
Writeln(Sender.ClassName);
end;
Var
O : TMyTestObject;
PI : PPropInfo;
NO : TNotifyObject;
M : TMethod;
Procedure PrintMethod (Const M : TMethod);
begin
If (M.Data=Pointer(NO)) Then
If (M.Code=Pointer(@TNotifyObject.Notification1)) then
Writeln('Notification1')
else If (M.Code=Pointer(@TNotifyObject.Notification2)) then
Writeln('Notification2')
else
begin
Write('Unknown method adress (data:');
Write(hexStr(Longint(M.data),8));
Writeln(',code:',hexstr(Longint(M.Code),8),')');
end;
end;
begin
O:=TMyTestObject.Create;
NO:=TNotifyObject.Create;
O.NotifyEvent:=@NO.Notification1;
PI:=GetPropInfo(O,'NotifyEvent');
Writeln('Method property : ');
Write('Notifying : ');
O.Notify;
Write('Get (name) : ');
M:=GetMethodProp(O,'NotifyEvent');
PrintMethod(M);
Write('Notifying : ');
O.Notify;
Write('Get (propinfo) : ');
M:=GetMethodProp(O,PI);
PrintMethod(M);
M.Data:=No;
M.Code:=Pointer(@NO.Notification2);
SetMethodProp(O,'NotifyEvent',M);
Write('Set (name,Notification2) : ');
M:=GetMethodProp(O,PI);
PrintMethod(M);
Write('Notifying : ');
O.Notify;
Write('Set (propinfo,Notification1) : ');
M.Data:=No;
M.Code:=Pointer(@NO.Notification1);
SetMethodProp(O,PI,M);
M:=GetMethodProp(O,PI);
PrintMethod(M);
Write('Notifying : ');
O.Notify;
O.Free;
end.

#### GetObjectProp

Declaration:
  Function GetObjectProp(Instance: TObject; const PropName: string): TObject;
  Function GetObjectProp(Instance: TObject; const PropName: string; MinClass:TClass): TObject;
  Function GetObjectProp(Instance: TObject; PropInfo: PPropInfo; MinClass: TClass): TObject;
Description:
  GetObjectProp returns the object which the property descroibed by PropInfo with name Propname points to for object Instance.

  If MinClass is specified, then if the object is not descendent of class MinClass, then Nil is returned.

Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid method property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  SetMethodProp (856), GetOrdProp (843), GetStrProp (849), GetFloatProp (837), GetInt64Prop (838), GetSetProp (848), GetObjectProp (842), GetEnumProp (836)

Listing: typinfex/ex5.pp

program example5;
{ This program demonstrates the GetObjectProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
NO1,NO2 : TNamedObject;
begin
O:=TMyTestObject.Create;
NO1:=TNamedObject.Create;
NO1.ObjectName:='First named object';
NO2:=TNamedObject.Create;
NO2.ObjectName:='Second named object';
O.ObjField:=NO1;
Writeln('Object property : ');
PI:=GetPropInfo(O,'ObjField');
Write('Property class : ');
Writeln(GetObjectPropClass(O,'ObjField').ClassName);
Write('Value : ');
Writeln((O.ObjField as TNamedObject).ObjectName);
Write('Get (name) : ');
Writeln((GetObjectProp(O,'ObjField') As TNamedObject).ObjectName);
Write('Get (propinfo) : ');
Writeln((GetObjectProp(O,PI,TObject) as TNamedObject).ObjectName);
SetObjectProp(O,'ObjField',NO2);
Write('Set (name,NO2) : ');
Writeln((O.ObjField as TNamedObject).ObjectName);
SetObjectProp(O,PI,NO1);
Write('Set (propinfo,NO1) : ');
Writeln((O.ObjField as TNamedObject).ObjectName);
O.Free;
end.

#### GetObjectPropClass

Declaration:
  Function GetObjectPropClass(Instance: TObject; const PropName: string): TClass;
Description:
  GetObjectPropClass returns the declared class of the property with name PropName. This may not be the actual class of the property value.
Errors:
  No checking is done whether Instance is non-nil. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  SetMethodProp (856), GetOrdProp (843), GetStrProp (849), GetFloatProp (837), GetInt64Prop (838)

For an example, see GetObjectProp (842).

#### GetOrdProp

Declaration:
  Function GetOrdProp(Instance : TObject;PropInfo : PPropInfo) : Longint;
  Function GetOrdProp(Instance: TObject;const PropName: string): Longint;
Description:
  GetOrdProp returns the value of the ordinal property described by PropInfo or with name PropName for the object Instance. The value is returned as a longint, which should be typecasted to the needed type.

  Ordinal properties that can be retrieved include:

  Integers and subranges of integers
    The value of the integer will be returned.
  Enumerated types and subranges of enumerated types
    The ordinal value of the enumerated type will be returned.
  Sets
    If the base type of the set has less than 31 possible values. If a bit is set in the return value, then the corresponding element of the base ordinal class of the set type must be included in the set.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid ordinal property of Instance Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  SetOrdProp (857), GetStrProp (849), GetFloatProp (837), GetInt64Prop (838),GetMethodProp (839), GetSetProp (848), GetObjectProp (842), GetEnumProp (836)

Listing: typinfex/ex1.pp

program example1;
{ This program demonstrates the GetOrdProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
begin
O:=TMyTestObject.Create;
Writeln('Boolean property : ');
Writeln('Value : ',O.BooleanField);
Writeln('Ord(Value) : ',Ord(O.BooleanField));
Writeln('Get (name) : ',GetOrdProp(O,'BooleanField'));
PI:=GetPropInfo(O,'BooleanField');
Writeln('Get (propinfo) : ',GetOrdProp(O,PI));
SetOrdProp(O,'BooleanField',Ord(False));
Writeln('Set (name,false) : ',O.BooleanField);
SetOrdProp(O,PI,Ord(True));
Writeln('Set (propinfo,true) : ',O.BooleanField);
O.Free;
end.

#### GetPropInfo

Declaration:
  Function GetPropInfo(AClass: TClass; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  Function GetPropInfo(AClass: TClass; const PropName: string): PPropInfo;
  Function GetPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  Function GetPropInfo(Instance: TObject; const PropName: string; AKinds: TTypeKinds) : PPropInfo;
  Function GetPropInfo(TypeInfo: PTypeInfo;const PropName: string) : PPropInfo;
  Function GetPropInfo(TypeInfo: PTypeInfo;const PropName: string; AKinds : TTypeKinds) : PPropInfo;
Description:
  GetPropInfo returns a pointer to the TPropInfo record for a the PropName property of a class. The class to examine can be specified in one of three ways:
  Instance
    An instance of the class.
  AClass
    A class pointer to the class.
  TypeInfo
    A pointer to the type information of the class.

  In each of these three ways, if AKinds is specified, if the property has TypeKind which is not included in Akinds, Nil will be returned.

Errors:
  If the property PropName does not exist, Nil is returned.
See also:
  GetPropInfos (845),GetPropList (846)

For an example, see most of the other functions.

#### GetPropInfos

Declaration:
  Procedure GetPropInfos(TypeInfo: PTypeInfo;PropList: PPropList);
Description:
  GetPropInfos stores pointers to the property information of all published properties of a class with class info TypeInfo in the list pointed to by Proplist. The PropList pointer must point to a memory location that contains enough space to hold all properties of the class and its parent classes.
Errors:
  No checks are done to see whether PropList points to a memory area that is big enough to hold all pointers.
See also:
  GetPropInfo (844),GetPropList (846)

Listing: typinfex/ex12.pp

Program example12;
{ This program demonstrates the GetPropInfos function }
uses
rttiobj,typinfo;
Var
O : TMyTestObject;
PT : PTypeData;
PI : PTypeInfo;
I,J : Longint;
PP : PPropList;
prI : PPropInfo;
begin
O:=TMyTestObject.Create;
PI:=O.ClassInfo;
PT:=GetTypeData(PI);
Writeln('Property Count : ',PT^.PropCount);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
GetPropInfos(PI,PP);
For I:=0 to PT^.PropCount-1 do
begin
With PP^[i]^ do
begin
Write('Property ',i+1:3,': ',name:30);
writeln(' Type: ',TypeNames[typinfo.PropType(O,Name)]);
end;
end;
FreeMem(PP);
O.Free;
end.

#### GetPropList

Declaration:
  Function GetPropList(TypeInfo : PTypeInfo; TypeKinds : TTypeKinds; PropList : PPropList) : Integer;
Description:
  GetPropList stores pointers to property information of the class with class info TypeInfo for properties of kind TypeKinds in the list pointed to by Proplist. PropList must contain enough space to hold all properties.

  The function returns the number of pointers that matched the criteria and were stored in PropList.

Errors:
  No checks are done to see whether PropList points to a memory area that is big enough to hold all pointers.
See also:
  GetPropInfos (845), GetPropInfo (844)

Listing: typinfex/ex13.pp

Program example13;
{ This program demonstrates the GetPropList function }
uses
rttiobj,typinfo;
Var
O : TMyTestObject;
PT : PTypeData;
PI : PTypeInfo;
I,J : Longint;
PP : PPropList;
prI : PPropInfo;
begin
O:=TMyTestObject.Create;
PI:=O.ClassInfo;
PT:=GetTypeData(PI);
Writeln('Total property Count : ',PT^.PropCount);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
J:=GetPropList(PI,OrdinalTypes,PP);
Writeln('Ordinal property Count : ',J);
For I:=0 to J-1 do
begin
With PP^[i]^ do
begin
Write('Property ',i+1:3,': ',name:30);
writeln(' Type: ',TypeNames[typinfo.PropType(O,Name)]);
end;
end;
FreeMem(PP);
O.Free;
end.

#### GetPropValue

Declaration:
  Function GetPropValue(Instance: TObject; const PropName: string): Variant;
  Function GetPropValue(Instance: TObject; const PropName: string; PreferStrings: Boolean): Variant;
Description:
  Due to missing Variant support, GetPropValue is not yet implemented. The declaration is provided for compatibility with Delphi.
Errors:
See also:

#### GetSetProp

Declaration:
  Function GetSetProp(Instance: TObject; const PropInfo: PPropInfo; Brackets: Boolean): string;
  Function GetSetProp(Instance: TObject; const PropName: string): string;
  Function GetSetProp(Instance: TObject; const PropName: string; Brackets: Boolean): string;
Description:
  GetSetProp returns the contents of a set property as a string. The property to be returned can be specified by it’s name in PropName or by its property information in PropInfo.

  The returned set is a string representation of the elements in the set as returned by SetToString (859). The Brackets option can be used to enclose the string representation in square brackets.

Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid ordinal property of Instance Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  SetSetProp (858), GetStrProp (849), GetFloatProp (837), GetInt64Prop (838),GetMethodProp (839)

Listing: typinfex/ex7.pp

program example7;
{ This program demonstrates the GetSetProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
Function SetAsString (ASet : TMyEnums) : String;
Var
i : TmyEnum;
begin
result:='';
For i:=mefirst to methird do
If i in ASet then
begin
If (Result<>'') then
Result:=Result+',';
Result:=Result+MyEnumNames[i];
end;
end;
Var
S : TMyEnums;
begin
O:=TMyTestObject.Create;
O.SetField:=[mefirst,meSecond,meThird];
Writeln('Set property : ');
Writeln('Value : ',SetAsString(O.SetField));
Writeln('Ord(Value) : ',Longint(O.SetField));
Writeln('Get (name) : ',GetSetProp(O,'SetField'));
PI:=GetPropInfo(O,'SetField');
Writeln('Get (propinfo) : ',GetSetProp(O,PI,false));
S:=[meFirst,meThird];
SetOrdProp(O,'SetField',Integer(S));
Write('Set (name,[mefirst,methird]) : ');
Writeln(SetAsString(O.SetField));
S:=[meSecond];
SetOrdProp(O,PI,Integer(S));
Write('Set (propinfo,[meSecond]) : ');
Writeln(SetAsString(O.SetField));
O.Free;
end.

#### GetStrProp

Declaration:
  Function GetStrProp(Instance : TObject; PropInfo : PPropInfo) : Ansistring;
  Function GetStrProp(Instance: TObject; const PropName: string): string;
Description:
  GetStrProp returns the value of the string property described by PropInfo or with name PropName for object Instance.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid string property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  SetStrProp (859), GetOrdProp (843), GetFloatProp (837), GetInt64Prop (838),GetMethodProp (839)

Listing: typinfex/ex3.pp

program example3;
{ This program demonstrates the GetStrProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
begin
O:=TMyTestObject.Create;
PI:=GetPropInfo(O,'AnsiStringField');
Writeln('String property : ');
Writeln('Value : ',O.AnsiStringField);
Writeln('Get (name) : ',GetStrProp(O,'AnsiStringField'));
Writeln('Get (propinfo) : ',GetStrProp(O,PI));
SetStrProp(O,'AnsiStringField','First');
Writeln('Set (name,''First'') : ',O.AnsiStringField);
SetStrProp(O,PI,'Second');
Writeln('Set (propinfo,''Second'') : ',O.AnsiStringField);
O.Free;
end.

#### GetTypeData

Declaration:
  Function GetTypeData(TypeInfo : PTypeInfo) : PTypeData;
Description:
  GetTypeData returns a pointer to the TTypeData record that follows after the TTypeInfo record pointed to by TypeInfo. It essentially skips the Kind and Name fields in the TTypeInfo record.
Errors:
  None.
See also:

#### GetVariantProp

Declaration:
  Function GetVariantProp(Instance : TObject;PropInfo : PPropInfo): Variant;
Description:
  Due to mising Variant support, the GetVariantProp function is not yet implemented. Provided for Delphi compatibility only.
Errors:
See also:
  SetVariantProp (860)

#### IsPublishedProp

Declaration:
  Function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;
  Function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
Description:
  IsPublishedProp returns true if a class has a published property with name PropName. The class can be specfied in one of two ways:
  AClass
    A class pointer to the class.
  Instance
    An instance of the class.
Errors:
  No checks are done to ensure Instance or AClass are valid pointers. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  IsStoredProp (852), PropIsType (853)

Listing: typinfex/ex10.pp

program example10;
{ This program demonstrates the IsPublishedProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
begin
O:=TMyTestObject.Create;
Writeln('Property tests : ');
Write('IsPublishedProp(O,BooleanField) : ');
Writeln(IsPublishedProp(O,'BooleanField'));
Write('IsPublishedProp(Class,BooleanField) : ');
Writeln(IsPublishedProp(O.ClassType,'BooleanField'));
Write('IsPublishedProp(O,SomeField) : ');
Writeln(IsPublishedProp(O,'SomeField'));
Write('IsPublishedProp(Class,SomeField) : ');
Writeln(IsPublishedProp(O.ClassType,'SomeField'));
O.Free;
end.

#### IsStoredProp

Declaration:
  Function IsStoredProp(Instance : TObject;PropInfo : PPropInfo) : Boolean;
  Function IsStoredProp(Instance: TObject; const PropName: string): Boolean;
Description:
  IsStoredProp returns True if the Stored modifier evaluates to True for the property described by PropInfo or with name PropName for object Instance. It returns False otherwise. If the function returns True, this indicates that the property should be written when streaming the object Instance.

  If there was no stored modifier in the declaration of the property, True will be returned.

Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  IsPublishedProp (851), PropIsType (853)

Listing: typinfex/ex11.pp

program example11;
{ This program demonstrates the IsStoredProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
begin
O:=TMyTestObject.Create;
Writeln('Stored tests : ');
Write('IsStoredProp(O,StoredIntegerConstFalse) : ');
Writeln(IsStoredProp(O,'StoredIntegerConstFalse'));
Write('IsStoredProp(O,StoredIntegerConstTrue) : ');
Writeln(IsStoredProp(O,'StoredIntegerConstTrue'));
Write('IsStoredProp(O,StoredIntegerMethod) : ');
Writeln(IsStoredProp(O,'StoredIntegerMethod'));
Write('IsStoredProp(O,StoredIntegerVirtualMethod) : ');
Writeln(IsStoredProp(O,'StoredIntegerVirtualMethod'));
O.Free;
end.

#### PropIsType

Declaration:
  Function PropIsType(AClass: TClass; const PropName: string; TypeKind: TTypeKind): Boolean;
  Function PropIsType(Instance: TObject; const PropName: string; TypeKind: TTypeKind): Boolean;
Description:
  PropIsType returns True if the property with name PropName has type TypeKind. It returns False otherwise. The class to be examined can be specified in one of two ways:
  AClass
    A class pointer.
  Instance
    An instance of the class.
Errors:
  No checks are done to ensure Instance or AClass are valid pointers.Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  IsPublishedProp (851), IsStoredProp (852), PropType (854)

Listing: typinfex/ex16.pp

program example16;
{ This program demonstrates the PropIsType function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
begin
O:=TMyTestObject.Create;
Writeln('Property tests : ');
Write('PropIsType(O,BooleanField,tkBool) : ');
Writeln(PropIsType(O,'BooleanField',tkBool));
Write('PropIsType(Class,BooleanField,tkBool) : ');
Writeln(PropIsType(O.ClassType,'BooleanField',tkBool));
Write('PropIsType(O,ByteField,tkString) : ');
Writeln(PropisType(O,'ByteField',tkString));
Write('PropIsType(Class,ByteField,tkString) : ');
Writeln(PropIsType(O.ClassType,'ByteField',tkString));
O.Free;
end.

#### PropType

Declaration:
  Function PropType(AClass: TClass; const PropName: string): TTypeKind;
  Function PropType(Instance: TObject; const PropName: string): TTypeKind;
Description:
  Proptype returns the type of the property PropName for a class. The class to be examined can be specified in one of 2 ways:
  AClass
    A class pointer.
  Instance
    An instance of the class.
Errors:
  No checks are done to ensure Instance or AClass are valid pointers. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  IsPublishedProp (851), IsStoredProp (852), PropIsType (853)

Listing: typinfex/ex17.pp

program example17;
{ This program demonstrates the PropType function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
begin
O:=TMyTestObject.Create;
Writeln('Property tests : ');
Write('PropType(O,BooleanField) : ');
Writeln(TypeNames[PropType(O,'BooleanField')]);
Write('PropType(Class,BooleanField) : ');
Writeln(TypeNames[PropType(O.ClassType,'BooleanField')]);
Write('PropType(O,ByteField) : ');
Writeln(TypeNames[PropType(O,'ByteField')]);
Write('PropType(Class,ByteField) : ');
Writeln(TypeNames[PropType(O.ClassType,'ByteField')]);
O.Free;
end.

#### SetEnumProp

Declaration:
  Procedure SetEnumProp(Instance: TObject; const PropInfo: PPropInfo; const Value: string);
  Procedure SetEnumProp(Instance: TObject; const PropName: string; const Value: string);
Description:
  SetEnumProp sets the property described by PropInfo or with name PropName to Value. Value must be a string with the name of the enumerate value, i.e. it can be used as an argument to GetEnumValue (837).
Errors:
  No checks are done to ensure Instance or PropInfo are valid pointers. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetEnumProp (836), SetStrProp (859), SetFloatProp (855), SetInt64Prop (855),SetMethodProp (856).

For an example, see GetEnumProp (836).

#### SetFloatProp

Declaration:
  Procedure SetFloatProp(Instance : TObject; PropInfo : PPropInfo; Value : Extended);
  Procedure SetFloatProp(Instance: TObject; const PropName: string; Value: Extended);
Description:
  SetFloatProp assigns Value to the property described by PropInfo or with name Propname for the object Instance.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid float property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetFloatProp (837), SetOrdProp (857), SetStrProp (859), SetInt64Prop (855),SetMethodProp (856)

For an example, see GetFloatProp (837).

#### SetInt64Prop

Declaration:
  Procedure SetInt64Prop(Instance: TObject; PropInfo: PPropInfo; const Value: Int64);
  Procedure SetInt64Prop(Instance: TObject; const PropName: string; const Value: Int64);
Description:
  SetInt64Prop assigns Value to the property of type Int64 that is described by PropInfo or with name Propname for the object Instance.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid Int64 property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetInt64Prop (838), GetMethodProp (839), SetOrdProp (857), SetStrProp (859), SetFloatProp (855)

For an example, see GetInt64Prop (838).

#### SetMethodProp

Declaration:
  Procedure SetMethodProp(Instance : TObject;PropInfo : PPropInfo; const Value : TMethod);
  Procedure SetMethodProp(Instance: TObject; const PropName: string; const Value: TMethod);
Description:
  SetMethodProp assigns Value to the method the property described by PropInfo or with name Propname for object Instance.

  The type TMethod of the Value parameter is defined in the SysUtils unit as:

       TMethod = packed record
         Code, Data: Pointer;
       end;

  Data should point to the instance of the class with the method Code.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid method property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetMethodProp (839), SetOrdProp (857), SetStrProp (859), SetFloatProp (855), SetInt64Prop (855)

For an example, see GetMethodProp (839).

#### SetObjectProp

Declaration:
  Procedure SetObjectProp(Instance: TObject; PropInfo: PPropInfo; Value: TObject);
  Procedure SetObjectProp(Instance: TObject; const PropName: string; Value: TObject);
Description:
  SetObjectProp assigns Value to the the object property described by PropInfo or with name Propname for the object Instance.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid method property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetObjectProp (842), SetOrdProp (857), SetStrProp (859), SetFloatProp (855), SetInt64Prop (855), SetMethodProp (856)

For an example, see GetObjectProp (842).

#### SetOrdProp

Declaration:
  Procedure SetOrdProp(Instance : TObject; PropInfo : PPropInfo; Value : Longint);
  Procedure SetOrdProp(Instance: TObject; const PropName: string; Value: Longint);
Description:
  SetOrdProp assigns Value to the the ordinal property described by PropInfo or with name Propname for the object Instance.

  Ordinal properties that can be set include:

  Integers and subranges of integers
    The actual value of the integer must be passed.
  Enumerated types and subranges of enumerated types
    The ordinal value of the enumerated type must be passed.
  Subrange types
    of integers or enumerated types. Here the ordinal value must be passed.
  Sets
    If the base type of the set has less than 31 possible values. For each possible value; the corresponding bit of Value must be set.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid ordinal property of Instance. No range checking is performed. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetOrdProp (843), SetStrProp (859), SetFloatProp (855), SetInt64Prop (855),SetMethodProp (856)

For an example, see GetOrdProp (843).

#### SetPropValue

Declaration:
  Procedure SetPropValue(Instance: TObject; const PropName: string; const Value: Variant);
Description:
  Due to missing Variant support, this function is not yet implemented; it is provided for Delphi compatibility only.
Errors:
See also:

#### SetSetProp

Declaration:
  Procedure SetSetProp(Instance: TObject; const PropInfo: PPropInfo; const Value: string);
  Procedure SetSetProp(Instance: TObject; const PropName: string; const Value: string);
Description:
  SetSetProp sets the property specified by PropInfo or PropName for object Instance to Value. Value is a string which contains a comma-separated list of values, each value being a string-representation of the enumerated value that should be included in the set. The value should be accepted by the StringToSet (861) function.

  The value can be formed using the SetToString (859) function.

Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid ordinal property of Instance. No range checking is performed. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetSetProp (848), SetOrdProp (857), SetStrProp (859), SetFloatProp (855), SetInt64Prop (855),SetMethodProp (856), SetToString (859), StringToSet (861)

For an example, see GetSetProp (848).

#### SetStrProp

Declaration:
  procedure SetStrProp(Instance : TObject; PropInfo : PPropInfo; const Value : Ansistring);
  Procedure SetStrProp(Instance: TObject; const PropName: string; const Value: AnsiString);
Description:
  SetStrProp assigns Value to the string property described by PropInfo or with name Propname for object Instance.
Errors:
  No checking is done whether Instance is non-nil, or whether PropInfo describes a valid string property of Instance. Specifying an invalid property name in PropName will result in an EPropertyError exception.
See also:
  GetStrProp (849), SetOrdProp (857), SetFloatProp (855), SetInt64Prop (855),SetMethodProp (856)

For an example, see GetStrProp (849)

#### SetToString

Declaration:
  function SetToString(PropInfo: PPropInfo; Value: Integer) : String;
  function SetToString(PropInfo: PPropInfo; Value: Integer; Brackets: Boolean) : String;
Description:
  SetToString takes an integer representation of a set (as received e.g. by GetOrdProp) and turns it into a string representing the elements in the set, based on the type information found in the PropInfo property information. By default, the string representation is not surrounded by square brackets. Setting the Brackets parameter to True will surround the string representation with brackets.

  The function returns the string representation of the set.

Errors:
  No checking is done to see whether PropInfo points to valid property information.
See also:
  GetEnumName (835), GetEnumValue (837), StringToSet (861)

Listing: typinfex/ex18.pp

program example18;
{ This program demonstrates the SetToString function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
I : longint;
begin
O:=TMyTestObject.Create;
PI:=GetPropInfo(O,'SetField');
O.SetField:=[mefirst,meSecond,meThird];
I:=GetOrdProp(O,PI);
Writeln('Set property to string : ');
Writeln('Value : ',SetToString(PI,I,False));
O.SetField:=[mefirst,meSecond];
I:=GetOrdProp(O,PI);
Writeln('Value : ',SetToString(PI,I,True));
I:=StringToSet(PI,'mefirst');
SetOrdProp(O,PI,I);
I:=GetOrdProp(O,PI);
Writeln('Value : ',SetToString(PI,I,False));
I:=StringToSet(PI,'[mesecond,methird]');
SetOrdProp(O,PI,I);
I:=GetOrdProp(O,PI);
Writeln('Value : ',SetToString(PI,I,True));
O.Free;
end.

#### SetVariantProp

Declaration:
  Procedure SetVariantProp(Instance : TObject; PropInfo : PPropInfo; Const Value: Variant);
  Procedure SetVariantProp(Instance: TObject; const PropName: string; const Value: Variant);
Description:
  Due to missing Variant support, this function is not yet implemented. Provided for Delphi compatibility only.
Errors:
See also:

#### StringToSet

Declaration:
  function StringToSet(PropInfo: PPropInfo; const Value: string): Integer;
Description:
  StringToSet converts the string representation of a set in Value to a integer representation of the set, using the property information found in PropInfo. This property information should point to the property information of a set property. The function returns the integer representation of the set. (i.e, the set value, typecast to an integer)

  The string representation can be surrounded with square brackets, and must consist of the names of the elements of the base type of the set. The base type of the set should be an enumerated type. The elements should be separated by commas, and may be surrounded by spaces. each of the names will be fed to the GetEnumValue (837) function.

Errors:
  No checking is done to see whether PropInfo points to valid property information. If a wrong name is given for an enumerated value, then an EPropertyError will be raised.
See also:
  GetEnumName (835), GetEnumValue (837), SetToString (859)

For an example, see SetToString (859).

[prev] [prev-tail] [front] [up]