Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I pass an object property by reference?
Message
From
28/02/2001 10:46:29
 
 
To
27/02/2001 17:48:43
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00480283
Message ID:
00480540
Views:
13
>I don't know first hand, but I doubt you'll find this functionality in other languages either. If you want to be able to change the property in a subroutine, pass a reference to the object. I think that the ability to pass a property by reference would lead to some hairy referencing issues, as well as some behind the scenes complications for any environment. For instance- does passing the property by reference increase the object's reference count?

The other languages I was refering to are VB and Java in particular (I'm pretty sure that it can be done in C++ since an array is but a pointer and anything passed as a pointer is the equivalent of being passed by reference but I'm not 100% sure).

In VB, you specify the way a parameter is passed in the receiving function with the reserved words ByRef or ByVal. So the function knows that it will receive a variable and that whatever changes occur in that variable will affect the original variable that was passed. Plus, I don't think that you can specify either ByVal or ByRef for an array in VB because arrays are always used by reference.

In Java, all natural types (int, char, float, etc.) are passed by value and all objects (String, Frame, etc.) are passed by reference. It is very simple and so, for example, if you wanted to pass a "natural type" variable by reference, you would need to store it in an object to do it. This is, now that I think of it, a little like what you would need to do in VFP.

Anyway, thank you all very much for your inputs, I will rebuild my function so that it can take either an array or an entire object as a reference.

Thanks again, Stephane.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform