Share via


AddProperty Method

Adds a new property to an object.

Object.AddProperty(cPropertyName [, eNewValue [, nVisibility [, cDescription]]])

Return Value

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.

  • nVisibility
    Specifies the visibility of the new property. Available for use at design-time, however, a value of 1 can be specified at runtime.

    nVisibility

    Visibility

    1

    Public

    2

    Protected

    3

    Hidden

  • cDescription
    Specifies a description for the new property. Available only at design-time.

    The property description is limited to 255 characters.

Remarks

Applies To: CheckBox Control | Collection Class | Column Object | ComboBox Control | CommandButton Control | CommandGroup Control | Container Object | Control Object | Cursor Object | CursorAdapter Class | Custom | DataEnvironment Object | EditBox Control | Exception Class | 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 | ReportListener Object | _SCREEN | Separator Object | Session Object | Shape Control | Spinner Control | TextBox Control | Timer Control | ToolBar Object

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 does not 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).

The AddProperty( ) method only works with some native Visual FoxPro objects. You can use the ADDPROPERTY( ) function to add a property to any object that Visual FoxPro works with, such as COM objects or those created with the SCATTER...NAME property. For more information, see ADDPROPERTY( ) function.

See Also

Reference

DEFINE CLASS Command

NewObject Method

SaveAs Method (Visual FoxPro)

SaveAsClass Method

Other Resources

Methods (Visual FoxPro)

Language Reference (Visual FoxPro)