Yes. In fact, this specific example was part of my presentation at the Xojo conference.
[quote=21630:@Kem Tekinay]Why wouldn’t an extension method work there? I’m envisioning something like:
Sub Add(Extends ByRef var As Integer, value As Integer)
var = var + value
End Sub
[/quote]
You can’t use ByRef with expressions.
And I just learned something new.
Please, why ByRef can’t be used with expressions?
Please explain. I can use it.
//Module Inc Integers
Sub Inc (byref i As Integer)
i = i+1
End Sub
Sub Inc (byref i As Integer) As Integer
i = i+1
Return i
End Sub
// Window
// Button Action - Showing Byref used in a expression
Sub Action()
Dim n As Integer
Inc(n)
MsgBox "This is n : "+str(Inc(n))
End Sub
Ah! I read previous posts. I believe Joe meant “You can’t use ByRef with extensions”.
That’s not what Joe was talking about. You cannot pass the result of an expression to a ByRef parameter.
foo.bar.baz is an expression. It exists in a temporary variable somewhere. Passing that temp variable ByRef just doesn’t make sense. It wouldn’t have the desired result. The value of the temporary variable would be updated, not the original value. It would remain unchanged.
Hi Norman,
from your post I must assume that ByRef keyword it is very different from a variable referenced by a pointer like in C language.
Or I’m missing something?
Well, [quote=21659:@Norman Palardy]The expression may give back a copy of an object - so you don’t modify what you think you’re modifying.
The expression may give back a read only item (ie a read only computed property) so it’s syntactically invalid.
Lots of reasons[/quote]
I wasn’t talking about passing an expression by reference, this is simply impossible and should lead to a compiler error. I first understood Maurizio question like “using ByRef IN expressions”, and I used in my example via my Inc(byref) function.
And I was not talking of using the keyword right in the expression even.
Hi Rick,
now we are alone…
Norman never was here?
So what we need is an Inline modifier Or, actually, a compiler that understands when it is better to inline a method vs. not, thus it would happen automagically behind the scenes.
No Maurizio. He’s a busy and helpful guy. Sometimes people just go away take care of other things. You can’t be frustrated if sometimes we don’t get some replies. But about this topic, I believe we all have enough info.
Hi Rick,
don’t worry.
I find Norman very professional and the value of his posts.
(but also I consider deleting a post a very hilarious thing)
[quote=21661:@Maurizio Rossi]Hi Norman,
From your post I must assume that ByRef keyword it is very different from a variable referenced by a pointer like in C language.
Or I’m missing something?[/quote]
Byref is sort of like a pointer - but the problem is not that it’s a pointer or not.
We’re actually writing something more definitive than my quick post - hence why I removed it.
An off-topic Pro tip: Never play pool against Norman for stakes. Ever.
No pool tables at the Monte Carlo
Hello Norman,
now I feel all the ByRef stuff really confusing.
A reference to a variable, by definition, can’t give you back anything since there is only one variable and the pointer itself, as a variable, does not exist.
What I found strange is “I can get back something different”.
I found all of this discussion very confusing.
English it is not my native language so I’m supposing I misunderstood something (like the pool…)
Some code example would be more appropriate.
Regards
Not Xojo, but explains ByRef in Italian: http://msdn.microsoft.com/it-it/library/eek064h4.aspx
I am aiming to get together a detailed response, for what it’s worth. I just haven’t had time due to something else coming up.