[Overview][Constants][Types][Classes][Procedures and functions][Index] Reference for unit 'typinfo' (#rtl)

GetOrdProp

Get the value of an ordinal property

Declaration

Source position: typinfo.pp line 345

function GetOrdProp(

  Instance: TObject;

  PropInfo: PPropInfo

):Int64;

function GetOrdProp(

  Instance: TObject;

  const PropName: string

):Int64;

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

  

Set value of an ordinal property

GetStrProp

  

Return the value of a string property.

GetFloatProp

  

Return value of floating point property

GetInt64Prop

  

return value of an Int64 property

GetMethodProp

  

Return value of a method property

GetSetProp

  

Return the value of a set property.

GetObjectProp

  

Return value of an object-type property.

GetEnumProp

  

Return the value of an enumeration type property.

Example

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.

Documentation generated on: Nov 16 2015