AddProperty Method
Applies To See Also
Adds a new property to an object.
Syntax
Object.AddProperty(cPropertyName [, eNewValue])
Returns
Logical
Arguments
cPropertyName
Specifies the name of the new property to add to the object.
eNewValue
Specifies the value to which the new property is set. If eNewValue is omitted, the value of the new property is unchanged if the property already exists or is set to false (.F.) for a new property.
Remarks
The AddProperty( ) method allows you to add a property to an object at runtime. The new property is added as a PUBLIC property.
You can also create property arrays for an object. Every element in the property array is initialized to eNewValue if it is included, otherwise every property array element contains false (.F.). The following code demonstrates how you can create a property array for an object:
oMyForm = CREATEOBJECT('Form')
oMyForm.AddProperty('MyArray(2)', 1) && Add an array as a property
oMyForm.MyArray(2) = 'Two'
CLEAR
? oMyForm.MyArray(1) && Displays 1
? oMyForm.MyArray(2) && Displays Two
If a property with the name you specify doesn’t exist, the property is created and a logical true (.T.) is returned.
If a property already exists with the name you specify, then AddProperty( ) returns the following:
- True (.T.) if the new property is an array property and the existing property is also an array property. The size of the array is re-dimensioned to that of the new array. If a value is specified with eNewValue, all the elements in the array are set to its value. If eNewValue is omitted, all the array elements are set to false (.F.).
- True (.T.) if the new property is not an array property and the existing property is an array property. The property remains an array property. If a value is specified with eNewValue, all the elements in the array are set to its value. If eNewValue is omitted, the array elements remain unchanged.
- True (.T.) if the new property is not an array property and the existing property is not an array property or is not a read-only Visual FoxPro native property. If a value is specified with eNewValue, the existing property is set to its value. If eNewValue is omitted, the existing property value remains unchanged.
- False (.F.) if the new property is an array property and the existing property is not an array property. The existing property remains unchanged.
- A “Property <PropertyName> is read-only” error is generated if the existing property is a read-only Visual FoxPro native property such as the BaseClass property.
- An “Incorrect property name” error is generated if the property name is not valid (the property name contains a space or other illegal characters).