Objects in Visual FoxPro

How do you set a Visual FoxPro class or array as the value of a property of another VFP class?

It appears that if you add a property to a VFP class, you can only set its value to a string, number, or T/F value.

I have two answers for you.


Let’s focus on the array first. The trick with the array property is including its dimensions in the property name.

For example, let’s say that you want to add an array property (3 rows, 3 columns) called aInfo to a class.

If you are creating a class in the Class Designer or Form Designer:

  1. Choose ClassNew Property (from the Class Designer) or FormNew Property (from the Form Designer).
  2. Type the following:

  3. Press the Add button.

Here is an example of creating the property in a programmatically defined class (i.e., stored in a PRG file):


The definition of the property must occur before the first PROC/FUNC in the class.


Now for the object reference. Let’s say you have a form to which you want to add an object reference called oData. The oData object needs to point to an instance of a class called MyDataObject.

There are several ways to define an object reference. The first way is to add a property to the form and then execute the following code (from the Init method of the form):

LOCAL loDataloData = CREATEOBJECT("MyDataObject")this.oData = loData

This approach makes it necessary to manually release the object reference before the form is destroyed. Otherwise the data object becomes a dangling object reference and the form will not release. When it is time to destroy the form you should do the following:

this.oData = .NULL.

The second way to add an object reference is to use the AddObject method. In this case, you do not add a property to the form. You could put the following code into the Init method of the form:


Note how you provide the property name in the first parameter and the name of the class in the second parameter. AddObject is only a method of containers so this only applies to forms, toolbars, and containers?and the custom class.

Dropping things from the toolbar onto the designer is the equivalent of calling AddObject.

To add classes programmatically, you need to use ADD OBJECT (see DEFINE CLASS for more help). Here is an example:


Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS