Board index » delphi » read/write a published property by name

read/write a published property by name

You can use RTTI to achieve what you want. Look in help for TypInfo unit
routnies.

Ex :
For Reading:
If IsPublishedProp(Button2, 'Left') Then
  tmp:=GetPropValue(Button2, 'Left', True);

For Writing:
If IsPublishedProp(Button2, 'Left') Then
  SetPropValue(Button2, 'Left', tmp);

HTH,
Vikram

Quote
"Ma?l H?rz" <ma...@web.de> wrote in message news:3d45c724_1@dnews...
> Hello,

> I have two components of the same type: let's take TButton.
> Now at runtime I want to assign some of the published properties of
Button1
> the same values as Button2 has.  (example: Button1.Left := Button2.Left;)
> With typinfo I will get at runtime a list of the published properties
names
> of the Buttons as strings. Then the user can select which of these have to
> be changed in Button1 to the values of Button2.
> All the other properties should be left unchanged.

> My problem more concrete:
> ----------------------------
> Is there a way to read/write a published property at runtime, knowing only
> that my component is of class TButton and the name of that property is
> 'Left'.
> Something like:

> tmp:=ReadProperty('Left', Button2);
> WriteProperty('Left', Button1, tmp)

> Thank you.

 

Re:read/write a published property by name


Hello,

I have two components of the same type: let's take TButton.
Now at runtime I want to assign some of the published properties of Button1
the same values as Button2 has.  (example: Button1.Left := Button2.Left;)
With typinfo I will get at runtime a list of the published properties names
of the Buttons as strings. Then the user can select which of these have to
be changed in Button1 to the values of Button2.
All the other properties should be left unchanged.

My problem more concrete:
----------------------------
Is there a way to read/write a published property at runtime, knowing only
that my component is of class TButton and the name of that property is
'Left'.
Something like:

tmp:=ReadProperty('Left', Button2);
WriteProperty('Left', Button1, tmp)

Thank you.

Re:read/write a published property by name


Thanks.

Other Threads