Why Create Properties

From RAD Studio
Jump to: navigation, search

Go Up to Creating properties Index


From the application developer's standpoint, properties look like variables. Developers can set or read the values of properties as if they were fields. (About the only thing you can do with a variable that you cannot do with a property is pass it as a var parameter.)

Properties provide more power than simple fields because:

  • Application developers can set properties at design time. Unlike methods, which are available only at run time, properties let the developer customize components before running an application. Properties can appear in the Object Inspector, which simplifies the programmer's job; instead of handling several parameters to construct an object, the Object Inspector supplies the values. The Object Inspector also validates property assignments as soon as they are made.
  • Properties can hide implementation details. For example, data stored internally in an encrypted form can appear unencrypted as the value of a property; although the value is a simple number, the component may look up the value in a database or perform complex calculations to arrive at it. Properties let you attach complex effects to outwardly simple assignments; what looks like an assignment to a field can be a call to a method which implements elaborate processing.
  • Properties can be virtual. Hence, what looks like a single property to an application developer may be implemented differently in different components.

A simple example is the Top property of all VCL controls. Assigning a new value to Top does not just change a stored value; it repositions and repaints the control. And the effects of setting a property need not be limited to an individual component; for example, setting the Down property of a speed button to True sets the Down property of all other speed buttons in its group to False.