Unit 'TypInfo' Package
[Overview][Constants][Types][Classes][Procedures and functions][Index] [#rtl]

GetObjectProp

Return value of an object-type property.

Declaration

Source position: typinfo.pp line 1271

function GetObjectProp(

  Instance: TObject;

  const PropName: string

):TObject;

function GetObjectProp(

  Instance: TObject;

  const PropName: string;

  MinClass: TClass

):TObject;

function GetObjectProp(

  Instance: TObject;

  PropInfo: PPropInfo

):TObject;

function GetObjectProp(

  Instance: TObject;

  PropInfo: PPropInfo;

  MinClass: TClass

):TObject;

Description

GetObjectProp returns the object which the property described 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

  

Set the value of a method property.

GetOrdProp

  

Get the 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.

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 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,ObjectNamedObject).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.

Documentation generated on: Dec 21 2024