Freigeben über


AddProperty Method

Adds a new property to an object.

Object.AddProperty(cPropertyName [, eNewValue])

Return Values

Logical

Parameters

  • 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 makes it possible for you to add a property to an object at run time. 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 redimensioned 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).

See Also

DEFINE CLASS | NewObject Method | SaveAs Method | SaveAsClass Method

Applies To: ActiveDoc Object | CheckBox Control | Column Object | ComboBox Control | CommandButton Control | CommandGroup Control | Container Object | Control Object | Cursor Object | Custom | DataEnvironment Object | EditBox Control | Form Object | FormSet Object | Grid Control | Header Object | Image Control | Label Control | Line Control | ListBox Control | OLE Bound Control | OLE Container Control | OptionButton Control | OptionGroup Control | Page Object | PageFrame Control | ProjectHook Object | Relation Object | _SCREEN | Separator Object | Session Object | Shape Control | Spinner Control | TextBox Control | Timer Control | ToolBar Object