

Note If you looked carefully, you might have noticed the empty parenthesis after the method name. It is commonly used to clean up the environment when an object is being released. The generic object-oriented term for this type of event method is called a destructor.
VFP DEFINE CLASS CODE
The Destroy event causes code defined in the Destroy() event method to be executed. The Destroy event is invoked by Visual Foxpro whenever an object is destroyed. It is commonly used to initialize properties of the object, or to ensure the environment is correctly setup before the object is used. The generic object-oriented term for this type of event method is called a constructor. The Init event causes code defined in the Init() event method to be executed. The Init event is invoked by Visual Foxpro whenever an object is created. Let’s modify our transaction class definition to show how the Init() and Destroy() event methods work: ? oCreditCardTransaction.Class & Prints “Transaction” on screen OCreditCardTransaction = CREATEOBJECT(“Transaction”) *- Create an instance of the Transaction class and print the

Through the power of inheritance, we automatically inherit any properties and methods defined in the class that we are subclassing, and thus can treat them as if they were actual members of our new classes: More precisely, we are subclassing a Visual Foxpro base class. These statements create new classes based on Visual Foxpro’s built-in classes. When creating new classes, we use the new DEFINE CLASS command: Just be sure to place the CREATEOBJECT() function calls before any class definitions! The code that follows can be typed directly into a PRG. While it’s possible and probably more desirable to create all your classes, including non-visual ones, using the Class Designer, it’s easier and more straightforward in a chapter of this nature to demonstrate the features of the language in code. Invoked when an error occurs inside one of the object’s methods You can place code in a command button’s Click() event method that will automatically run whenever the button is clicked.Īll Visual Foxpro base classes can respond to a common minimum set of events: Event For example, when the user clicks on a command button, Visual Foxpro invokes the Click event. In Visual Foxpro, object can also respond to events that occur in the system. Most objects also exhibit some kind of behavior in the form of methods.
VFP DEFINE CLASS FREE
You are free to add custom properties to any new class you create. The name of the class of the parent class of the object
VFP DEFINE CLASS FULL
The full path of the class library where this class is defined All Visual Foxpro base classes share a common minimum set of properties: Property Here is the current list of base classes:Īn object has properties used to describe the object, or to hold values that represent the object’s state. The form is referred to as the Parent, while the text boxes are referred to as children (or child controls). A good example of a container is a form that contains a group of text boxes. (The “control” control is somewhat of an exception to this rule, since it allows us to refer to multiple controls as if they were one). The difference is that a container can include other controls or even other containers within itself, while a control cannot. These built-in classes are called base classes.īase classes are grouped into controls and containers. The model includes a set of built-in classes that you use as a basis for creating your own classes. User defined classes, protected class members, inheritance, - everything you would expect to find in a robust object model. The Visual Foxpro object model is based on a strong foundation of object-oriented principles. Alan Griver, ISBN 0-7821-1648-5, Copyright ©1995 SYBEX Inc.,by permission of SYBEX Inc. This article is excerpted from The Visual FoxPro® 3 Codebook by Y.
