The last two examples describe how to create classes interactively by using the Class Designer, or you can programmatically create a class. But it's cumbersome to create classes in this way, and it takes a lot of patience to debug, relatively small.
To expand the knowledge bar, this article on the programming method to define the sentence format of the class to do a simple introduction, but there is no need to delve into and waste too much time, after all, there is already a visual, powerful "Class designer" can be used, otherwise VFP these three letters, the beginning of this V (Visual) also lost its meaning. A simple sample code for programmatically creating a class is given at the end of this article, and the Run-time interface is as follows:
At run time click the blank place of the form to touch the Click event of the publication, update the Caption property value of the label control after the pop-up dialog box, and the form becomes the following image:
VFP uses the Define class statement to define classes and to specify properties, events, and methods for classes and subclasses at the same time. Let's take a look at the format of the Define Class statement:
DEFINE class Name 1 as base class name
[[Protected Property Name table]
Property name = Expression
...]
[ADD Object [Protected] object name as Class Name 2 [Noinit]
[with property name = Expression,...]
... [[Protected] function| PROCEDURE object reference. Sequence of event name
statements
[endfunc| Endproc] ...
]
Enddefine
Description
(a) To create an object using a class defined by the Define class, you can use the Creatobject () function in your program.
(ii) Parameter "class name 1" Specifies the name of the class to be created, and the base class name indicates the parent class of a class or subclass that can be the system base class for VFP or another user-defined class.
(iii) The protected property name table prevents access to or changes to the properties of an object from outside the definition of a class or subclass.
(iv) Add object adds a target from a VFP base class, user-defined class, subclass, and OLE custom control to a gray or subclass definition. Protected prevents accessing or altering the attributes of an object from outside the definition of a class or subclass. Protected keyword must be placed in front of the object, otherwise VFP will generate a syntax error.
(v) "as Class Name 2" indicates the name of the class or subclass that contains the object in the Join class definition. Parameter noinit indicates that the Init method is not executed when an object is added. The With property name = expression indicates the list of properties and property values of an object added to a class or subclass definition.
(vi) function (function) or procedure (procedure) can create an event and method within a class or subclass definition to end Endfunc or Endproc.
(vii) A class defined with the Define class is a set of commands that, like procedures in a program, are generally placed behind a program.
(eight) Sample code:
Public Myform
myform=createobject ("Form1") && building objects by defining form Classes
myform.width=290
myform.caption= " Programming starter Web-programmatically creating classes and Forms "
myform.closable=.f. && Disable the form's Close button
myform.autocenter=.t.
Myform.show
myform.circle (60,100,150,1)
READ EVENTS
DEFINE class Form1 as form && define form class
ADD OBJECT COMM1 as CommandButton; && Define a command button in the form with
caption= "Exit", backcolor=2,left=40
ADD OBJECT Label1 as Label; && define the label in the form with
top=60,left=40,autosize=.t.,caption= "Are you Ready?"
PROCEDURE Click
=messagebox ("form's Click event!") ")
thisform. label1.caption= "Programming Network" I wish you all a good study! "
endproc
PROCEDURE COMM1. Click
MESSAGEBOX ("hello!")
Thisform. Release clear
EVENTS
endproc
enddefine
Save the above code as "programmatically creating classes and forms." PRG ", run the program file.
This example code is debugged in the win2003+vfp6.0 environment.
See the full set of "rookie also learn VFP" tutorial