Component Writer's Guide :: Adding properties
To add a property to your component, you have two options:
- Public properties
- Published properties
The main difference between public and published properties is that published properties are the only one shown on the Object Inspector, read more on their respective sections.
Public properties are suited to be used on Custom components, Custom components usually are the ones that provide most of the functionality and you inherit from them publishing the functionality you need.
To create a public property:
protected $_testproperty="default"; function readTestProperty() { return $this->_testproperty; } function writeTestProperty($value) { $this->_testproperty=$value; }
When you add these functions to your component, you can write sentences like this:
$MyFirstComponent->TestProperty="value"; echo $MyFirstComponent->TestProperty;
That is, the read and write functions are interfaces to the protected $_testproperty variable and are called in the appropiate time, all this is due PHP magic functions (__set and __get) which the RPCL uses for the purpose of add properties to the language.
And now, if you want the user to be able to use that property from design time, you need to publish that property, by writting the setters/getters:
function getTestProperty() { return $this->readTestProperty(); } function setTestProperty($value) { $this->writeTestProperty($value); }
As you can see, they call the read/write versions of the property, but that's the way the IDE is able to know which properties to show on the Object Inspector and which not.