RAD Studio VCL Reference
TypInfo.SetPropValue Function

Sets the value of a component property using a variant value.

procedure SetPropValue(Instance: TObject; const PropName: string; const Value: Variant); overload;
procedure SetPropValue(Instance: TObject; PropInfo: PPropInfo; const Value: Variant); overload;
SetPropValue(TObject * Instance, const AnsiString PropName, const Variant Value);
SetPropValue(TObject * Instance, PPropInfo PropInfo, const Variant Value);

SetPropValue utilises Delphi's RTTI (Run Time Type Information) to set the value of a component's property using a variant value.  

In one form of this function, the object Instance's property is defined by a PropInfo record. GetPropInfo and GetPropList can be used to obtain such a record.  

In the other form of this function, the name of the property, PropName, is explicitly given.  

In both forms of the function, the new property value is defined by Value. Note that only certain property assignments are possible using variants. It is normally be used when using GetPropValue from another property.  

The intrinsic value of this function is to allow setting of component properties without the need to hard code the property name. This allows mass visual component processing at run time.

Note: If the specified property does not exist, or is not a published property, an EPropertyError exception is thrown.


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!