Compartir a través de


MemberClass Property

Specifies the name of the member class to use when adding new members to a container. Read/write at design time and run time.

For a Column parent container and its header members, use the HeaderClass property instead of MemberClass.

Note

If the member class is based on a class that is stored in a program (.prg) file, make sure that the compiled program (.fxp) file is synchronized with the .prg file.

Object.MemberClass [ = cClassName ]

Return Value

  • cClassName
    Specifies the name of a member class in a program (.prg) or visual class library (.vcx) file.

Remarks

Applies To: PageFrame Control | CommandGroup Control | OptionGroup Control | Grid Control

Visual FoxPro creates a member object using MemberClass under the following conditions:

  • MemberClass is specified for a container class definition at design time. When Visual FoxPro creates the container, it instantiates members using MemberClass.

  • The member object's Count property, such as the PageCount, ButtonCount, or ColumnCount properties, is increased at run time. If the member object's Count property is programmatically or interactively increased, Visual FoxPro adds new instances using MemberClass.

    Note

    The ColumnCount property is unique in that you can specify its value as -1 or 0. All other Count properties must be greater than or equal to zero.

Both MemberClass and MemberClassLibrary support the Access and Assign methods and Public, Hidden and Protected scope.

A container can hold objects of different member classes with the same base class. For example, suppose you have a PageFrame object and two member classes, myPage1 and myPage2, defined as Page classes. You can specify myPage1 for the PageFrame MemberClass property at design time and change PageFrame MemberClass to myPage2 at run time, followed by an increase in the PageFrame PageCount property.

The MemberClass and MemberClassLibrary properties have the following additional behaviors at design time and run time:

  • Behavior at design time

    When setting the MemberClass and MemberClassLibrary properties at design time, you are prompted to destroy existing member classes, including property settings; new, added, or modified method code; and added objects.

    When you create a subclass from a container that specifies the MemberClass property, the subclass inherits the proper MemberClass and MemberClassLibrary properties, which you can modify.

    Visual FoxPro displays the MemberClass and MemberClassLibrary properties in the Properties window as read-only. However, you can set these properties in the Properties window by clicking the ellipsis (...) button to display the Open dialog box, browsing for, and selecting the member class and class library you want to use.

    Note

    If you want to specify a member class for the container, you must set, not only one, but both MemberClass and MemberClassLibrary properties.

    If you are setting the member object's Count property in a program (.prg) file at design time, you must specify the member object's Count property after setting the MemberClass and MemberClassLibrary properties because of certain dependencies. For example:

    DEFINE CLASS myPageFrame AS PageFrame
       MemberClassLibrary = 'MyPages.prg'
       MemberClass = 'myPage'
       PageCount = 3
    ENDDEFINE
    

    When using the ASELOBJ( ) function to set the MemberClass and MemberClassLibrary properties individually, the following behavior occurs:

    • If you specify only the MemberClass or MemberClassLibrary property using the ASELOBJ() function, Visual FoxPro does not generate an error but disregards the property specified and uses the base class when adding a new member object.

    • If the member object's Count property is 0 (or -1 for Grid objects), Visual FoxPro does not perform error checking when setting MemberClass and MemberClassLibrary, which you can set in any order.

    • If the member object's Count property is greater than 0, Visual FoxPro performs error checking when MemberClass is set. Therefore, in this situation, you need to set MemberClassLibrary before setting MemberClass.

      Note

      If either property is invalid, Visual FoxPro generates the appropriate message if the class or class library is invalid and sets the member object's Count property back to 0.

      If both MemberClass and MemberClassLibrary are valid, Visual FoxPro recreates all existing member classes based on the new member class, and all previous member object data is lost.

      Warning

      Visual FoxPro does not prompt you to destroy existing member classes, including property settings; new, added, or modified method code; and added objects when setting MemberClass and MemberClassLibrary in code.

      As when setting the member object's Count property in a program (.prg) file at design time, you must specify the member object's Count property after setting the MemberClass and MemberClassLibrary properties.

      You can change MemberClassLibrary to another class library that has the same MemberClass. If you increase the member object's Count property, Visual FoxPro adds a new member class using the new MemberClassLibrary. Though the designer displays member classes from different class libraries, only the most recent MemberClassLibrary persists when saving the class. Therefore, when you instantiate or open the class again, all member objects are created from the most recent MemberClassLibrary.

  • Behavior at run time

    Changing MemberClass and MemberClassLibrary affects only newly created member objects, not existing member objects in the container. You can also use the AddObject and NewObject methods, which function as usual, to specify a different class.

    Note

    You should specify both MemberClass and MemberClassLibrary properties at run time. If you specify only MemberClass or MemberClassLibrary at run time, Visual FoxPro does not generate an error; however, it uses the base class when adding a new member and disregards the property specified.

    To reliably determine the member class used to instantiate a particular member object, use the Class and ClassLibrary properties of the member object instead of MemberClass and MemberClassLibrary because the latter properties can change at run time.

    Note

    A container can have member objects derived from different member classes.

    Visual FoxPro does not support the capability to specify a class in a class library bound inside a compiled Visual FoxPro application (.app).

Example

The following example creates a form, adds a PageFrame container to the form, defines the PageFrame container as "myPageFrame", sets the MemberClassLibrary and MemberClass properties for "myPageFrame", defines a Page member object as "myPage", and adds code for a command button and events.

PUBLIC x
x = CREATEOBJECT("form")
x.ADDOBJECT("pf1","myPageFrame")
x.pf1.Visible = .T.
x.Show()

DEFINE CLASS myPageFrame AS PageFrame
   MemberClassLibrary = 'myPages.PRG'
   MemberClass = 'myPage'
   PageCount = 2
   TabOrientation = 1
ENDDEFINE

DEFINE CLASS myPage AS Page
   ADD OBJECT cmd1 AS commandbutton WITH ;
      Caption = "Hello", FontBold = .T.
   PROCEDURE Init
      THIS.Caption = "Funpage"+TRANSFORM(THIS.Parent.PageCount)
   ENDPROC
   PROCEDURE cmd1.Click
      MESSAGEBOX(this.Caption)
      THIS.Parent.Parent.PageCount = THIS.Parent.Parent.PageCount+1
   ENDPROC
ENDDEFINE

See Also

Reference

Member Classes (Visual FoxPro)

MemberClassLibrary Property

HeaderClass Property

HeaderClassLibrary Property

ASELOBJ( ) Function

Other Resources

Properties (Visual FoxPro)