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

FindPropInfo

Return property information by property name.

Declaration

Source position: line 0

function FindPropInfo(

  Instance: TObject;

  const PropName: String

):PPropInfo;

function FindPropInfo(

  AClass: TClass;

  const PropName: String

):PPropInfo;

Description

FindPropInfoexamines 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 EPropertyErrorexception will be raised. The GetPropInfofunction has the same function as the FindPropInfofunction, but returns Nilif the property does not exist.

Errors

Specifying an invalid property name in PropNamewill result in an EPropertyErrorexception.

See also

GetPropInfo

  

Return property type information, by property name.

GetPropList

  

Return a list of a certain type of published properties.

GetPropInfos

  

Return a list of published properties.

Example

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.