Partager via


Member Classes

You can define and create subclasses for member objects of certain container objects. The following table lists these members and their parent containers:

Member Container
Page PageFrame
CommandButton CommandGroup
OptionButton OptionGroup
Column Grid
Header Column

Using member classes, you can define consistent behavior for all members of a specific class. For example, you can define a particular behavior in the Activate event of a Page class to be used in a specific PageFrame class or object. All member pages for that page frame inherit the same code or behavior.

To set the default custom class for member objects, set the MemberClassLibrary and MemberClass properties for the PageFrame, CommandGroup, OptionGroup, and Grid container classes. These properties specify the member class and class library you want to use. When these properties are set, new member objects inherit from the specified member class. For Column objects, use the HeaderClassLibrary and HeaderClass properties to specify a custom Header class.

**Caution   **Do not change the Name property for a member class in a program (.prg) -based class definition at design time. Doing so can result in generating the message, "Class definition name is not found."

Remarks

In general, member objects must be contained within a parent container object to be used visually. Parent containers can contain only member objects. For example, a Page object must be in a PageFrame object to display on a Form object and a PageFrame object must have at least one Page object to be visible on a Form object. There are two exceptions:

  • You can use command buttons in other containers without requiring a CommandGroup.
  • Column objects can contain other controls but only one Header.

Member objects exist only as children of the parent container, which contains only members belonging to a specific base class. For example, the existence of a Page object requires the prior existence of its parent PageFrame container object. A PageFrame object can contain only pages and not command buttons.

You can associate an event when adding a new member object using the member object's count property _ASSIGN method. The member object's Init event occurs when member objects are added. However, you cannot pass parameters to the Init event of a newly created member object because members are created dynamically when the parent container's count property changes. If you need to pass parameters, you can use the container's AddObject method.

Note   On an .scx form, if you add instantiation code to the member class's Init event, Visual FoxPro disregards that code and only the Init code for the member class definition runs. However, with visual class library (.vcx) forms, Visual FoxPro creates a true subclass. You can safely add instantiation code for other events such as Click.

Any property values accessed in the member class's Init event belong to those of the original member class. Any values that might have been overridden in the subclass are applied after instantiating the member class.

These behaviors apply only to .scx forms. After the Init event occurs, the member class is treated the same on .scx and .vcx forms.

See Also

Objects, Collections, and Classes | Page Object | PageFrame Control | CommandButton Control | CommandGroup Control | OptionButton Control | OptionGroup Control | Grid Control | Column Object | Header Object | MemberClass Property| MemberClassLibrary Property | HeaderClass Property | HeaderClassLibrary Property | Init Event | AddObject Method