Look at the case study VFP: The use of new classes

Source: Internet
Author: User
Tags new features

I. Use of the new definition class

(i) Add new classes to the form

A new class that is stored in a class library should be opened or registered before it is used, and you can open or register the class library in the following three ways:

1. Use the project Manager:

Select the Classes tab in the Project manager and click Add to appear in the Open dialog box. In the Open dialog box, select a class library and open it. The class library that you open will be added to the project. We can drag a class from the project manager to either the form designer or Class Designer, or you can display them directly on the form Control toolbar in the form designer or Class designer, and the They are then added to the form or to other containers using the method of adding standard controls.

2. Using the Options dialog box:

Click the Options menu item in the VFP main menu to eject the Options dialog box. In the dialog box, select the Controls tab. If you want the new class to appear on the VFP Control toolbar, select Set Default.

3. You can use the View Class button on the Form Control toolbar to register a class library, select Add from the shortcut menu that appears, and add the class library to the form Controls toolbar.

(ii) Override default property settings

After adding an object based on the new class to the form, we can modify all the unprotected properties of the object being created to override its default property setting, and the overridden property value does not change even if the value of the property is modified in the Class Designer. However, if you do not modify the property settings of the objects in the form, the properties of the objects created on the Class Designer will change at the same time after you modify the properties of the class in the Class builder.

(iii) method of calling the parent class

The subclass of an object automatically inherits the functionality of the parent class, but it can also replace these inherited features with new features. For example, when a subclass is derived from a base class or when an object based on that class is added to a container and then reprogrammed to its click event, the code for the base class at run time does not run and the new code is run.

Two. Example: Create a record Move command button class tools and apply it in the form

1. Start Class Designer:

Click the new command under Files in the VFP menu bar, select Class, and then click the New File button to show the new Class dialog box.

Enter the name of the new class in the Class Name column of the new Class dialog box: Tools, in the "derived from" column, specify the base class for the new class: Commandgroup, enter the class library name and save path for the new class in the "stored in" column: E:\MYVFP\TOOLS.VCX, as shown in the following illustration:

When you have set the above options and click OK in the dialog box, the system opens Class Designer, as shown in the following figure:

Because the base class for this example is a command button group, the system defaults to producing 2 command buttons at the start, and we can edit the new class in Class designer just as you would edit a command button group in the form. The layout of the command button group in Class Designer, setting properties, and writing event code for an object are the same as the form designer.

2. command button layout and property settings:

The Buttoncount property value is set to 4 first in the Properties window, so that four command buttons (COMMAND1~COMMAND4) appear in the Class Designer, and the mouse-drag method Command1~command4 The four buttons horizontally, The Caption property values of the Command1~command4 four buttons are then set to the first, previous, Next, and last, and then properly resized, after the Class designer is set up, as shown in the following illustration:

3. Write event code:

The Click event code for the tools class:

Sel=this.value do case case sel=1 go top case
sel=2
   if!bof ()
      skip-1
   endif case
sel= 3
   if!eof ()
      Skip
	endif case
sel=4 go
   bottom
endcase
Thisform.refresh

4. Close Class Designer and save the tools class to the TOOLS.VCX class library according to the system's query to complete the creation of the new class.

5. Create a new form, design its Caption property as "use of new Class", set its Width property value to 250, and save as "use of new class. Scx".

6. Register a new class: Click the View Class button on the Form Control toolbar and select Add from the shortcut menu that appears, as shown in the following illustration:

7. Open Tools.vcx in the Open dialog box that appears, so that you can see this new class of tools in the Form Controls toolbar, as shown in the following illustration:

8. So that we can just like add other controls, click on the Tools class from the Form Controls toolbar, and then click in the form's margin, and an instance of the Tools class appears on the form: TOOLS1, as shown in the following illustration:

9. Right-click the blank space in the form, add the Site information table to the data environment, and then in the Data Environment Designer, drag each field in the Site information table to the bottom of the TOOLS1 control on the form, automatically generate several label controls and text box controls, and adjust the position of each control appropriately. After the adjustment, the following figure shows:

10. Save and run the "use of the new class. Scx", the interface as shown in the following image, click the Tools1 control on the "first", "Next" button, you can display in the form text box in the Web site information table corresponding to the record:

This example code is debugged in the win2003+vfp6.0 environment.

See the full set of "rookie also learn VFP" tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.