Skip to content

GetOrdProp

Get the value of an ordinal property

Declaration

Source position: typinfo.pp line 889

  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 typecast 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

Name Description
GetEnumProp Return the value of an enumeration type property.
GetFloatProp Return value of floating point property
GetInt64Prop return value of an Int64 property
GetMethodProp Return value of a method property
GetObjectProp Return value of an object-type property.
GetSetProp Return the value of a set property.
GetStrProp Return the value of a string property.
SetOrdProp Set value of an ordinal 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.