realbasic-nug
[Top] [All Lists]

Re: byVal not working with arrays?

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: byVal not working with arrays?
From: Will Leshner <leshner at ljug dot com>
Date: Tue, 31 May 2005 10:43:22 -0700
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20050317180027 dot 4312B7BABB0 at lists dot realsoftware dot com> <p06210273bec227fe56cb at [192 dot 168 dot 1 dot 2]>

On May 31, 2005, at 7:45 AM, Robert Woodhead wrote:

it actually gets passed by reference!

This is not good. It's either a bug, or if it is intended that byval not work with arrays, then it needs to be redlined in the documentation in 48pt font that it doesn't!


No, "it" gets passed ByVal, which is the default for all argument passing unless you say ByRef. Where I think you might be confused is what exactly what "it" is. For objects, and arrays act like objects when passed as arguments, what gets passed is a *reference* to the array. And it is that reference that is passed by value. Which means that if you assign a new array to the argument in the method, like this (assuming aArray is an array of Integers):

aArray = Array(1, 2, 3)

The caller's array will be unchanged. If, on the other hand, you declare aArray to be ByRef, then the above line of code would change aArray for the caller as well.


--
REALbasic database options: http://sqlabs.net
REALbasic news and tips: http://rbgazette.com
KidzMail & KidzLog: http://haranbanjo.com

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>