I would desperately like the ByRef keyword for arguments passed to subroutines in Basic for Android. Really will make static modules better in a reuseable sense.
Please ... please
I don't think that ByRef will be added as the underlying layer which is Java doesn't support it, and it will probably add too much overhead.
However you can easily mimic ByRef behavior using Type:
B4X:
Sub Process_Globals
Type ByRefInt (val As Int)
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim a, b As ByRefInt
a.val = 2
b.val = 3
s1(a, b)
Log("a = " & a.val & ", b = " & b.val) 'prints: a = 3, b = 6
End Sub
Sub s1 (n1 As ByRefInt, n2 As ByRefInt)
n1.val = n1.val + 1
n2.val = n2.val * 2
End Sub
Is it possible for this to work with a variable? It doesn't appear to be able to. With the new classes I want to set the text of a view and store a ref to the string variable that set it so in a way a variable can be tied to an EditText View and when the text of it changes the variable can be changed with it. Some way of determining if they passed a string like "My String" or an actual string variable...along with if the variable is still in scope may be needed too.
Strings are immutable. This means that when you change the string you are actually creating a new string object.
So changing the string will not have any effect on the view's text.
This cannot be changed as this is how the underlying system works.
Ok, I actually needed it the other way around where when the view's text is changed I change the text of the string in the text changed event of the view, but it sounds like there isn't a way of storing the ref to the string variable to do it.