Objects in Visual FoxPro

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:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as