Condividi tramite


DEClass Property

Specifies the name of the DataEnvironment class to use when adding a data environment to a form. Read/write at design time and read-only at run time.

At design time, DEClass makes it possible for you to specify a DataEnvironment class from the class library in the DEClassLibrary property.

Form.DEClass [= cClassName]

Return Value

  • cClassName
    Character data type. The cClassName parameter specifies one of the following:

    • Name of a programmatic class in a program (.prg) file

    • Name of a non-visual class in a visual class library (.vcx) file

Remarks

Applies To: Form Object

Visual FoxPro supports DEClass and DEClassLibrary for form (.scx), visual class library (.vcx), and program (.prg) files but not for FormSet objects or in the Report Designer.

Visual FoxPro instantiates a DataEnvironment object from DEClass and its associated DEClassLibrary property under the following conditions:

  • DEClass specifies a DataEnvironment class at design time in the Properties window for the form.

  • DEClass specifies a DataEnvironment class when programmatically creating the form.

When the form is created, Visual FoxPro uses the specified DataEnvironment class to create the DataEnvironment object. If you specify a value for the DEClassLibrary property but not for DEClass, or if the DataEnvironment class is the wrong type or does not exist in the class library specified, Visual FoxPro generates the appropriate message.

You can set DEClass and DEClassLibrary using the Properties window in the Form Designer, in a Form class, or from a class definition in a .prg file. Visual FoxPro displays DEClass and DEClassLibrary in the Properties window as read-only. However, clicking the ellipsis (...) button in the Properties window displays the Open dialog box so you can select a desired .prg file or, if supported, .vcx file.

You can also use the ASELOBJ( ) function to store object references to an array to set object properties individually. However, if you set only the DEClass or the DEClassLibrary property, Visual FoxPro disregards the settings for these properties and uses the default DataEnvironment class. You must set both properties.

Note

When setting the DEClass and DEClassLibrary properties using code or the ASELOBJ( ) function, you must set the DEClassLibrary property before setting the DEClass property.

When you open the Data Environment Designer by right-clicking the form, the following occurs:

  • DataEnvironment class containing Cursor objects

    If the contained cursor or cursors refer to an existing table or remote view, tables and views placed on the Data Environment Designer surface are read-only. You can drag and drop fields or tables on the Form Designer surface if the following properties are set with the specified requirements:

    • CursorSource (Required)   Table name and path if a free table; table name only if a database container (DBC) table.

    • Database (Optional)   Name and path of the DBC is filled in automatically if a DBC table or view.

    • Alias (Optional)   Alias assigned to the table if different from the table name. Otherwise, the alias defaults to the CursorSource name.

    If the DataEnvironment class contains a Cursor object, but the cursor does not contain a valid reference to a table or view, the Data Environment Designer does not open. Visual FoxPro loads the data environment after generating the appropriate message.

    If the DataEnvironment class contains multiple Cursor objects, only those cursors containing valid table and/or view references are placed on the Data Environment Designer surface. Cursors that do not contain valid table or view references are disregarded.

    If the cursor references a DBC, but the cursor does not reference a valid table or view in the DBC, Visual FoxPro loads the data environment after displaying the appropriate message.

    If the DataEnvironment class does not contain a Cursor object, the Data Environment Designer does not open, and Visual FoxPro generates an appropriate message.

    When you drag a table (.dbf) file from a folder to a form while a non-DataEnvironment class data environment is open, Visual FoxPro automatically adds the table to the data environment. However, if the opened data environment is based on a DataEnvironment class, the data environment is read-only, and Visual FoxPro does not add the .dbf file to the data environment.

  • DataEnvironment class containing CursorAdapter objects

    If the DataEnvironment class contains a CursorAdapter object, the CursorAdapter must meet the following requirements to appear on the Data Environment Designer surface:

    • The CursorAdapter CursorSchema property is specified and set to a valid value.

    • The CursorAdapter Alias property is specified.

    Note

    If the prior conditions are met, cursor adapters appear on the Data Environment Designer surface as read-only. You can drag and drop tables and fields on the form. The properties, events, or methods of the data environment and any contained CursorAdapter objects are read-only.

    The Data Environment Designer does not open if any of the following conditions are true:

    • The DataEnvironment class contains a CursorAdapter object, but the cursor adapter does not contain valid data in the CursorSchema property.

    • The CursorAdapter object does not instantiate for any reason.

To modify the DataEnvironment class, you must close the Form Designer, release any classes in use, modify and recompile the DataEnvironment class in the file specified by the DEClassLibrary property, and return to the Form Designer.

When the DEClass and DEClassLibrary properties are set, running the form creates and loads the data environment from the DataEnvironment class specified. To set DEClass and DEClassLibrary at run time, you must use code.

If you attempt to convert a form to a form set at design time when the Form Designer is open, and the DEClass and DEClassLibrary properties are specified for the form, Visual FoxPro generates the appropriate message. If a form set is open in the Form Designer, and you attempt add a form that specifies the DEClass and DEClassLibrary properties to the form set at design time, Visual FoxPro generates the appropriate message and makes the DEClass and DEClassLibrary properties unavailable. If you attempt to add a form that specifies the DEClass and DEClassLibrary properties to the form set at run time, Visual FoxPro disregards DEClass and DEClassLibrary and does not load the data environment class specified.

DEClass and DEClassLibrary supports Public, Hidden, and Protected scope.

DEClass and DEClassLibrary does not support Access and Assign methods.

In a subclassed form, DEClass and DEClassLibrary are inherited as normal.

Example

The following example creates a Form class and then sets the DEClassLibrary and DEClass properties to specify an external DataEnvironment class and class library.

DEFINE CLASS form1 as Form
   DEClassLibrary="MyProgram.prg"
   DEClass="MyDE"
ENDDEFINE

See Also

Reference

Form Object Properties, Methods, and Events
DEClassLibrary Property
PUBLIC Command
DataEnvironment Object

Concepts

Access and Assign Methods
Protecting and Hiding Class Members

Other Resources

Properties (Visual FoxPro)
Language Reference (Visual FoxPro)