Tutorials to .com

Tutorials to .com » Database » Foxpro » VFP Chapter VI Essentials object-oriented programming

VFP Chapter VI Essentials object-oriented programming

Print View , by: iSee ,Total views: 35 ,Word Count: 3662 ,Date: Sat, 18 Apr 2009 Time: 7:37 PM

6.1 an overview of object-oriented programming

1. The basic concepts of

Object-oriented programming through class, subclass, and objects such as embodied in the design, object-oriented programming is the core design technology.

Categories: the definition of the object features, as well as the appearance and behavior of the target template.

Class features:

Packaging: the hidden object category of data or operation of internal details, we can only see the appearance of information.


Any category can have from other derived classes, the new categories to keep the parent category and attributes, but with the addition of new features. Embodies the object-oriented design methods of sharing mechanisms.

Polymorphism: the same operation may be acting on multiple types of object, and obtain different results.

Abstract: a class or object extracting the characteristics of different, rather than the type or object to deal with all the information.

Base class:

Provided by the system itself as the base class type. Base class type and control, including types of containers. Container is a collection of other objects such as tables, option button groups; control is a single object, does not contain other objects, such as the command button, text box.


The definition of other categories as a starting point, the object of a new category created. New class will inherit any changes made to the parent category.


Storage type of documents, each a visual design class are stored in a Library. Library file extension. VCX.

Object: It is kind of an example, including data and processes. With the definition of class where all the attributes and methods.

VFP, there are two objects: container objects and control objects.

Attributes: control, field or the characteristics of database objects.

Event: the object identified by an action.

Methods: The object associated with the procedures implemented by a process, that is, to deal with the incident a group of code.

Users can not create a new target, but the method can create a new process.

2. Visual foxpro base class

From the Visual FoxPro base class, you can create a derived class or object.

Container Command group Control Fine-tuning Tags
Form Command button Check box OLE container control Lines
Form set Options Group List Box OLE bound control Separator #
Form Options button # Text box Custom Shape
# Header Frame Combo box Toolbar Image
Out # Page # Edit box Timer

Note: # of these categories is an integrated part of the parent container, in the Class Designer can not Subclassing.

Base class events in the smallest collection

Matter Description
Init Activated when the object was created.
Destroy When the object from memory when the activation of the release.
Error When the type of event or method error occurred during activation.

The minimum base class attributes collection

Properties Description
Class What sort of such.
BaseClass What kind of base class from derived from, for example, Form, Commandbutton or Custom, etc.
ClassLibrary Subordinate to what kind of library.
ParentClass Is based on the type of object. If they were directly from the Visual FoxPro base class derived from, the ParentClass attribute values with the same attribute value BaseClass.

Container Class

Type containers can contain other objects, and allow access to these objects. Each container can contain the object type as follows.

Container Can contain the object of
Command button group Command button
Container Arbitrary control
Control Arbitrary control
Form set Form, toolbar
Form Frames, arbitrary control, containers or custom object
Form out In addition to the header object and form, form set, toolbar, timer and other objects out of any object other than
Form Form out
Option button group Options button
Frame Page
Page Arbitrary controls, containers, and custom objects
Toolbar Arbitrary control, frames and containers

The creation of 6.2 category

1. The way to create a category

(1) Designer

(2) Form Designer

(3) programmatically

2. By type of design to create categories

VFP Chapter VI Essentials object-oriented programming

The use of "designer-type" Visualization can create and modify categories. Category is stored in the class library (. VCX) file.

(1) create a new category

Three methods can be used (the File menu, project Manager, CREATE CLASS command) to open the Class Designer and create a new category in which, and in the design will be able to see the final appearance of each object.


Click the File menu select New → Class → new file in the dialog box gives the name of the new category, the category based on the new and the preservation of the new category into the category of Class Designer → <→ base class as required in the based on the necessary changes to the closure of → Designer and identify preservation.

(2) For the type of design the appearance of the designated

1) for the type of set up a toolbar icon

Designer in the category from the category menu select the type of information category information → Open dialog box, in the tool box icon. BMP file name and path.


Toolbar icon. BMP files must be 15 x 16 pixel size. If the picture is too large or too small, it will be adjusted to 15 x 16 pixels, the graphics may be deformed.

2) to set up a container for the category icon

Open Class Designer category from the category menu to select the information icon in the container box → type designer in the form of the control button on the toolbar to display. BMP file name and path.

(3) create a class library

Three methods can be used to create class libraries.

1) create a class in the new dialog box, type "stored in" box to specify a new class library file.

2) CREATE CLASS command, specify the name of the new library.

For example, the following statement creates a new class called myclass and a new class library called new_lib:


3) use the command CREATE CLASSLIB.

For example, in the command window, type the following command, you can create a new_lib the categories:


(5) amend the class definition

In the creation of categories, you can modify it, to kind of changes would affect all sub-categories and based on all objects in this category. Can also increase the types of features or modify wrong category, all sub-categories and based on all objects of this class will be modified to inherit. The project manager to select the types of modifications or the use of modified MODIFY CLASS command.

(6) the form and save it as a type of control

Can be a form or control on the form save it as a subset of class definition. If you intend to create a sub-category based on the form, or in other forms of re-use of these controls can be a form to save as a class definition.

From the File menu select Save as type → type in the Save As dialog box, select the current selected control or form → in the "class name" box, enter the category name in the paper box → Save the file name type → select the OK button.

3. Programmatically create a category with

Window in the definition of the establishment of a category in the program file (extension. PRG), and then the implementation of the program.

4. Will be added to the form type, form sets and toolbar

(1) sign up for a class library

From the Tools menu, select Options → Options dialog box, select the Control tab → select video library and select the Add button in the Open dialog box → select the library to register and select Open → select the OK button.

(2) to increase the function of subclasses

Use scope operator (::) in the subclass call the parent class code, parent reference methods.

Call parent class method syntax is: ParentClass:: Method ()

(3) properties and methods will be added to the category

Be able to add new categories as many of the new attributes and new methods. Save a value attribute, and method call can save the process of running the code.

From the category menu to select the new attributes or new methods → Properties dialog box in the new property or method, type the name of → specify whether it protected.

5. Category browser

(1) the role of the browser

Can create sub-categories, the type of copy from a library to another library, classes and library files to delete, rename, or redefine the type of category relations.

Note: If you want to type to delete, rename, or re-definition of the form are based on the type of operation may not be correct.

(2) add a sub-class

In the category browser options open class → subclass derived from the class, and then select a new category button → <type in the new dialog box, enter a new subclass of → in the category defined in Designer and save the sub-class.

(3) the type of copy from a library to another library

In the category of open source browser from the Tools menu → Library to open the browser type of the second instance, and select the target library file in the source library → select category you want to copy, and then hold down the Ctrl key while category at the top of the list icon into the purpose of the class library on the class icon. Hold down the Ctrl key at the same time if it is mobile.

(4) the number of categories of documents from one library to another library to copy documents

In the class browser to open source class library → If you want to filter the list of categories, the filter box, type in the type of conditions to limit you want to copy from the file type → From the Tools menu, open the type of browser the second example, the and select the target document library → library in the source, select the library to copy documents, and then hold down the Ctrl key at the same time, the category list at the top of the category icon into the target database on the type of icon.

(5) to delete category, class or form

1) Open the browser type or form library.

2) In the category list, select the category you want to delete, class or form, and then select the Delete button. On the category, it records in the library marked delete marker, the next you can choose to clear the library; of class libraries and forms, the document is deleted from the disk.

(6) Rename the class Library,

In the class browser to open in the category → Library list, select the category you want to rename, and select Rename Rename button → category in the dialog box, enter the new name, then click Rename.

Note: If the relevant sub-class to rename the category, then sub-category name will not be able to invoke heavy inherited class attributes.

(7) changes in a parent class

In the class browser to open in the category → Library list, select the category you want to re-definition, and then select the custom button re-re-definition of → in the dialog box for box, enter the new class name of the Father. New parent and the original parent class must be derived from the same base class → based on box, select or enter the library file name.

(8) custom category browser

Type can change your browser's properties, events and methods. Procedures to operate through a browser type:

1) Open the browser category will automatically create a public variable _oBrowser, can use this variable to invoke a browser or operating type form, as the same object to any form.

2) To change the type of browser attributes set.

For example, in the open category of the browser before the adoption of the following command to type the title of the browser property is set to Hello:

_OBROWSER.Caption = "Hello"

_OBROWSER.Left = 10

3) Open the browser type and create a case in point.

For example, to open the Class browser, enter the code: DO (_BROWSER)

6.3 to create and deal with the object

1. Create Object

(1) programmatically

To create a category first, and then CREATEOBJECT () function to create.

(2) visualization methods

Designer with the creation of form.

2. Invoke the object

Reference object, between object and object, between object and attributes required separator. Separated.

(1) the absolute reference

From the highest levels of the reference container object, the object is given an absolute address. Such as: form1.text1.value

(2) the relative reference

Levels in the containers in a container relative to the reference level. Such as: thisform. Text1.value

Attributes or keywords Quote
ActiveControl Current activities with the focus of form controls
ActiveForm Form the current activities
ActivePage Activities form the current activities page
Parent The direct object containers
THIS The object
THISFORM Contains the object's form
THISFORMSET Form that contains the object set

System variables that _SCREEN screen objects, such as combination with ActiveForm do not know the form in the case of form processing activities.

3. Setting Object Properties

(1) can be carried out in the Properties window in Visual Settings

(2) can be used in the procedure set up the following format:

Reference object. Attribute = value

Such as: thisform. Text1.value = "As long as deep skills, an iron bar into a needle."

Would like to first set up a number of attributes can be used WITH ... ... ENDWITH statement.

Such as: WITH form1.text1
WITH form1.text1

4. Call object program

If the object has been created, applications can call anywhere in the object's method procedure. Method of procedure call format is: object reference. Method of procedure

Such as: Form1.Show

5. The object of the incident response

When the time of the incident, the incident will be the implementation of the code.

With MOUSE can be used programmatically generate an order CLICK, DOUBLECLICK, MOUSEMOVE, DRAGDROP events, use the ERROR command ERROR produced events, or have a KEYBOARD command KEYPRESS events can not be used in addition to other programming methods other events, but can be calls and their associated process.

6.4 event and Methods

1. vfp events

VFP event classification commonly used in

Event Type Event name
Mouse events Click DblClick RightClick DropDown DownClick UpClick
Keyboard events KeyPress
Control the content of change events InteractiveChange
Control the focus of the event GotFocus LostFocus When Valid
Form events Load Unload Destroy Activate Resize Paint QueryUnload
Incident data environment AfterCloseTable BeforeOpenTable
Project events QueryModifyFile such as
OLE events OLECompleteDrag such as
Other events Timer Init Destroy Error
Some of the core events and the trigger time
Matter Trigger time
Load When the form or forms set to be loaded when
Unload When the form or forms set released from memory when
Init When creating objects
Destroy Release object from memory when
Click The user object when the mouse click
DblClick Double-click the user object when the mouse
RightClick The user object when the right mouse button click
GetFocus When the target has been the focus of
LostFocus When the object loses focus
KeyPress Button when the user
MouseDown Press the mouse in the object
MouseUp Release the mouse in the object
MouseMove Move the mouse in the object
InteractiveChange .. Changes in the value of interactive objects
ProgrammaticChange Programmable to change the target value

2. Event loop

READ EVENTS command VFP6.0 with the establishment of the cycle, the CLEAR EVENTS command to terminate the cycle.

VFP6.0 applications using the design, it is important to create an event cycle, or not functioning properly. READ EVENTS command usually appears in the application of the main program, at the same time must ensure that out of the main program interface in order to issue the CLEAR EVENTS mechanisms, or procedures to enter the circle of death.

3. Methods

The common method VFP6.0

Name Call syntax Function
AddObject Object. AddObject (cName, cClass [, ...]) In the run-time added to the container object object
Clear Object.Clear Clear the list box or combo box content control
Hide Object.Hide By setting Visible attribute. F., to hide the form, the form or toolbar set
Show Object.Show The Visible property is set to. T., display and activate a set form or a form, and to determine the form display mode
Refresh Object.Refresh Redraw the form or control, and set all values
Release Object.Release Release form from memory or the form set
Quit Object.Quit VFP6.0 example the end of a return to the creation of its application.

FoxPro Tutorial Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.