Android Question Using SubDelayed2

Carthalion

Member
Licensed User
Longtime User
This is by Erel from an earlier thread. The answer is about how to send multiple variables from one activity to another.

Create a custom type with all this fields and send an instance of this type.

Can someone please elaborate on this, or even better, show an example?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Process_Globals
Type MyPoint (X As Int, Y As Int, Clr As Int)
End Sub

Sub PrintPoint (p As MyPoint)
Log(p.X)
End Sub

Sub SomeSub
Dim p As MyPoint
p.X = 100
p.Y = 200
CallSub2 (Me, "PrintPoint", p)
End Sub

You can also create a helper sub:
B4X:
Sub CreatePoint(X As Int, Y As Int, Clr As Int) As MyPoint
Dim p As MyPoint
p.Initialize '<-- not required in this case but it is still a good practice.
p.X = X
...
Return p
End Sub

CallSub2(Me, "PrintPoint", CreatePoint(100, 200, Colors.Red))
 
Upvote 0
Top