Objects in Visual FoxPro

Visual Studio 2005

When an object is created from a class, it exists as an instance of that class. The class describes the data, characteristics, and functionality for the objects created from that class. Objects in Visual FoxPro can be forms, form sets, controls, and so on. They also have properties and methods, which you can use to manipulate the objects, and they can detect and respond to events, which are occur when certain actions are performed. An object's properties, methods, and events are defined by the class it is created from.

You can create objects by using the Form Designer or the CREATEOBJECT( ) function. For more information, see Creating Objects from Classes, Form Designer, or CREATEOBJECT( ) Function.

Features of Objects

Objects possess the following features:

Object Properties

An object that you create in Visual FoxPro has properties, or attributes, that pertain specifically to that object. You can set and modify values for these properties, which determine the characteristics for the objects. You can set properties for Visual FoxPro objects at design time or run time, depending on the property.

For example, a computer has properties that can include the following: color, size, shape, location in a room, or state. Likewise, in Visual FoxPro, a check box created from the CheckBox control class includes the following properties:

For more information, see How to: Set Properties for Objects and How to: Add Properties to Classes.

Object Methods

An object has methods, which contain procedures for performing a specific task. However, object methods differ from standard Visual FoxPro procedures in that object methods are inextricably bound to an object and are called differently compared to standard Visual FoxPro procedures.

For example, a check box created from the CheckBox control class includes the following methods:

You can include methods in object events or use them independently outside events. When you use methods outside events, you must call them explicitly and programmatically. You can also create and extend methods. For more information, see How to: Call Methods and How to: Add Properties to Classes.

Object Events

An object can detect and respond to specific actions called events. An event is a specific and predetermined activity that occurs when the user or system performs an action. In most cases, events occur because of user interaction. In Visual FoxPro, user actions that trigger events include clicking or moving the mouse and pressing keys. System events include initializing an object and encountering a line of code that generates an error.

For example, a check box created from the CheckBox control class includes the following events:

Events can have methods associated with them. For example, when you include method code in a Click event, the code is executed when the Click event occurs. Though extensive, the set of events available is fixed. You cannot create new events.

For more information, see Events in Visual FoxPro.

See Also

Community Additions