Page 1 of 1
References and Values; Objects, Values and ByVal/ByRef
Posted: Fri Dec 01, 2006 9:14 pm
by Marilla
Guide removed. No longer available. Likely filled with factual errors, anyway :razz:
Posted: Mon Dec 04, 2006 1:55 am
by Lagoon
I'm adding a case where it's very good to use byref. Spometimes you need a function which returns more than a value. There are two ways to do this:
1) returning an array, a struct (I prefere to use a struct when returned variables have different types, but it's not mandatory) or (in some particular cases) a dictionary
2) passing any number of (uninitialized) variables by reference and setting their values inside the function
Posted: Mon Dec 04, 2006 2:53 am
by Marilla
Lagoon wrote:I'm adding a case where it's very good to use byref. Spometimes you need a function which returns more than a value. There are two ways to do this:
1) returning an array, a struct (I prefere to use a struct when returned variables have different types, but it's not mandatory) or (in some particular cases) a dictionary
2) passing any number of (uninitialized) variables by reference and setting their values inside the function
Yup, that can work too! COM programmers on Windows, for example, will recognize this as pretty much how everything is done. Since the return value is very often reserved for the 'HRESULT', or basically the status code, most values are gotten back by passing variables into reference parameters.
I personally don't like that way of doing things, because I think that returning a struct is usually a better option. For example, all of the Core functions that return multiple, but differing values do so as members of a struct (those that return multiple like values do so by returning an array).
However, this isn't at all an invalid use of this, and might come in handy for some folks; Thanks for adding it!

Posted: Mon Dec 04, 2006 5:18 am
by Lagoon
Recently I'm prefering the use of struct too ^_^
Posted: Mon Dec 04, 2006 9:29 pm
by Yukiko
*Copies thread to 'POL Knowledgebase folder'*