In VFP, the system-defined class is called the base class, and the user cannot modify it, but the object can be created directly from the base class to implement the instantiation of the class, such as the class on the form Control toolbar that we commonly use is the system base class. VFP's base class is divided into Container class (Container) and control class (controls) two kinds. Simply put, a container class is a class that can contain other objects, such as forms, containers, and so on, and a control class is a class that can no longer accommodate other objects, such as text boxes, command buttons, and so on.
The container classes for VFP include: Form set (FormSet), form (form), container (Container), page frame (pageframe), page (pages), table (grid), Columns (column), option button Group (optiongroup), command button groups (Commandgroup) and tools (Tool).
The control classes of VFP include: Tags (label), text Box (textbox), edit box (editbox), list box (ListBox), combo box (ComboBox), command button (CommandButton), check box (checkbox), controls, images (image), fine tuning (Spinner), Timers (Timmer), header (header), OLE bound controls (OLE Bound control), OLE container controls (OLE Container) , custom (custom), shape (shape), line, and separator (Separator).
On VFP class and object of knowledge, you can refer to the "VFP Basic Course" fourth chapter of the content.
VFP classes can be created interactively, either by using the Class Designer or the form designer, or programmatically, this article describes the more common ways to create classes using Class Designer interaction.
Using Class Designer in VFP, you can create visual and Non-visual classes, where visual classes refer to classes based on visual containers and controls, and Non-visual classes refer to classes based on custom classes. Visual classes are typically used in applications for control program input, output, and so on, while not visual classes are used to define a particular object or unit of data. The newly generated class is stored in the class library file (. VCX).
VFP Startup Class Designer has the following three ways:
(1). In the project manager, select the Classes tab, and then click the New button.
(2). Click the new command under Files in the VFP menu bar, select Class, and then click the New File button.
(3). Executes the Create Class command in a command window.
Using either of these methods, a new Class dialog box appears, as shown in the following illustration:
Selecting "Custom" in the "derived from" column of the dialog box creates a custom class and selects other base class names to extend the base class. After you fill in the Save location and file name in the "stored in" column below, clicking the OK button opens Class Designer, as shown in the following illustration:
I. Adding objects to a class
If the new class was created based on a container class, you can add controls to the class. You can select the control you want to add from the Form Controls toolbar and drag it to the Class designer and resize it. Some of the attributes and implications of the new class are shown in the following table:
Property |
Meaning |
Class |
The name of the new class |
BaseClass |
base class for new class |
ClassLibrary |
Library filename for new class |
ParentClass |
The parent class on which the object is based, such as the class that derives directly from the VFP base class, the ParentClass property value is the same as the BaseClass property value. |
Two. Add new attributes to the class
You can modify the properties that are already in the new class, or you can create new properties for the new class. If the properties of the new class are not modified or added, the new class inherits the properties of the parent class. To add a new property to a class:
When Class Designer opens, clicking New property under Classes in the VFP menu bar pops up the new Properties dialog box, as shown in the following figure:
The role of the various options for this dialog box:
(1) "Name": Enter the name of the property you want to add.
(2) "Visibility": Specifies at what level the property is to operate. Visibility is divided into public, protected and hidden three kinds, "public" as the default value, indicating that the object can be modified at design time; protection "means that it can be accessed only by a method program within the definition of the class, or by subclasses of the class, and cannot be modified after the class is instantiated, and" hide "means that only members defined within the class cannot be" seen " and references.
(3) "description": You can add a description of this attribute in this location.
When you click the Add button on the right side of the dialog box, the new property is added to the class, and when a new attribute is added, VFP defaults to logical false (. F.).
Three. Add a method program for the class:
Adding a method program is similar to adding a property, and clicking New Method program under Classes in the VFP menu under Class Designer opens the New Method Program dialog box, which is set in the dialog box.
Four. Specify an icon for the class:
The user can specify a display appearance for the class. In Class Designer, when you select the Class Information menu item from the Class main menu in the VFP system menu, the Class Information dialog box appears, as shown in the following illustration:
In the dialog box, in the toolbar icon and container icon boxes, you can enter the name and path of the BMP file, as shown above.
Description: Toolbar icon bmp file must be 15*16 pixel size, if the picture is too large or too small, it will be adjusted to 15*16 pixels, but may be distorted.
See the full set of "rookie also learn VFP" tutorial