On Feb 18, 2007, at 12:58 UTC, Tom Benson wrote: > OK, if that's the case then it's something I did not know. > > I always thought that ALL parameters were passed byval unless > explicitly passed byref.
That is correct. Andy's explanation is technically incorrect, though it's sort-of right in spirit. But it often causes confusion, so let's stick to what's technically correct. :) > Meaning that changes made to the passed > variable were not reflected in the original object. Right. > I now see that this is true only for base data types (strings, > integers, doubles etc). No, it's true for all variables of any type. But think carefully about what constitutes a "change made to the passed variable". If you do X = Y then you're making a change to the variable X. But if you do X.foo = Y then you're not making any change to variable X. X still points to exactly the same object that it did before. > Is there any harm in explicitly declaring the graphics parameter > byRef??? Yes, it adds extra unnecessary overhead, and also confuses the human reader, since it implies that you're going to be assigning some other graphics object to whatever variable is passed in. Moreover, you *can't* assign another value to an expression, so if you declare the parameter ByRef and then try to pass in an expression like "Canvas1.graphics," it won't compile. The rule is simple: if you don't intend to assign a new value to the caller's variable, then don't pass it ByRef. > I like explicitly declared code, I find it easier to keep > track of my variables. I'm really not a fan of the linker "taking > care of stuff" for me unless I explicitly declare it. I agree, but that's not what's going on here. I can see how you think that if you bought Andy's explanation that object variables are implicitly passed ByRef, but that's not the case. > It's what made > me start this thread in the first place (it was changing the name of > a parameter I passed ByRef from "CanvasName" to the expression > "self.CanvasName", and of course you can't pass expressions as ByRef) Right, there you go. Good example of why you shouldn't declare it ByRef if you don't actually intend to change the passed-in variable to refer to something else. Cheers, - Joe -- Joe Strout -- [EMAIL PROTECTED] Verified Express, LLC "Making the Internet a Better Place" http://www.verex.com/ _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
