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

GetOrdProp

Get the value of an ordinal property

Declaration

Source position: line 0

function GetOrdProp(

  Instance: TObject;

  PropInfo: PPropInfo

):Int64;

function GetOrdProp(

  Instance: TObject;

  const PropName: String

):Int64;

Description

GetOrdPropreturns the value of the ordinal property described by PropInfoor with name PropNamefor 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 Instanceis non-nil, or whether PropInfodescribes a valid ordinal property of InstanceSpecifying an invalid property name in PropNamewill result in an EPropertyErrorexception.

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.