References and Values; Objects, Values and ByVal/ByRef

Open discussion forum. For topics that do not fit anywhere else.
Post Reply
Marilla

References and Values; Objects, Values and ByVal/ByRef

Post by Marilla »

Guide removed. No longer available. Likely filled with factual errors, anyway :razz:
Last edited by Marilla on Sun Dec 17, 2006 8:50 am, edited 1 time in total.
Lagoon
Grandmaster Poster
Posts: 118
Joined: Sun Mar 05, 2006 7:25 am

Post 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
Marilla

Post 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!

8)
Lagoon
Grandmaster Poster
Posts: 118
Joined: Sun Mar 05, 2006 7:25 am

Post by Lagoon »

Recently I'm prefering the use of struct too ^_^
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

*Copies thread to 'POL Knowledgebase folder'*
Post Reply