Question

Is it possible in Visual Foxpro to have 2 variables that point to the same address in memory. Such that if the value of one of the variables is changed then the other is also changed. I understand that when passing arguments to functions they can be passed by value or reference but I want to know if this is possible in straight code. I think in other languages such as C this is called a pointer but I don't believe VFP has pointers. So if one writes the following code it will output the number 4.

 a=4
 b=a
 a=6
 ? b    && answer 4

But could one write code such as the following where the answer could be 6?

 a=4
 b=*a   && note the inclusion of the asterisk (pointer?) here which won't compile in VFP
 a=6
 ? b
Was it helpful?

Solution

No. There are no pointers or references in Foxpro; as you note, the closest thing to it is passing parameters by reference to functions. You might be able to try to kludge something together (as Jerry mentions) with objects using Access/Assign methods, but even then, all that gets passed to the Assign method is the value being assigned - nothing about whether it was originally another variable, a literal value, an object's property, etc.

You could simulate it by using an array or a table. The variables would contain only the array index or record number (or other index) as a reference, and you'd have to get the actual value from the array or table.

OTHER TIPS

Take a look at the Visual Foxpro Access and Assign Methods. These methods can be used to execute code when querying a property or trying to change the value of a property. Below is a link that shows an example:

Access and Assign Example

You could do something like this:

a=4
b='a'
a=6
?&b
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top