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: