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

GetSetProp

Return the value of a set property.

Declaration

Source position: typinfo.pp line 1237

function GetSetProp(

  Instance: TObject;

  const PropName: string

):string;

function GetSetProp(

  Instance: TObject;

  const PropName: string;

  Brackets: Boolean

):string;

function GetSetProp(

  Instance: TObject;

  const PropInfo: PPropInfo;

  Brackets: Boolean

):string;

Description

GetSetProp returns the contents of a set property as a string. The property to be returned can be specified by it's name in PropName or by its property information in PropInfo.

The returned set is a string representation of the elements in the set as returned by SetToString. The Brackets option can be used to enclose the string representation in square brackets.

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

SetSetProp

  

Set value of set-typed 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.

Example

program example7;

{ This program demonstrates the GetSetProp function }

{$mode objfpc}

uses rttiobj,typinfo;

Var
  O : TMyTestObject;
  PI : PPropInfo;

Function SetAsString (SetTMyEnums) : String;

Var
  i : TmyEnum;

begin
  result:='';
  or:=mefirst to methird do
    If i in Seten
      begin
      If (Result<>'') then
        Result:=Result+',';
      Result:=Result+MyEnumNames[i];
      end;
end;

Var
  S : TMyEnums;

begin
  O:=TMyTestObject.Create;
  O.SetField:=[mefirst,meSecond,meThird];
  Writeln('Set property    : ');
  Writeln('Value                        : ',SetAsString(O.SetField));
  Writeln('Ord(Value)                   : ',Byte(O.SetField));
  Writeln('Get (name)                   : ',GetSetProp(O,'SetField'));
  PI:=GetPropInfo(O,'SetField');
  Writeln('Get (propinfo)               : ',GetSetProp(O,PI,false));
  S:=[meFirst,meThird];
  SetOrdProp(O,'SetField',Byte(S));
  Write('Set (name,[mefirst,methird]) : ');
  Writeln(SetAsString(O.SetField));
  S:=[meSecond];
  SetOrdProp(O,PI,Byte(S));
  Write('Set (propinfo,[meSecond])    : ');
  Writeln(SetAsString(O.SetField));
  O.Free;
end.

Documentation generated on: Nov 23 2024