Wish Dinamically naming Controls/Nodes/Views

Cableguy

Expert
Licensed User
Longtime User
I am posting this WISH here but it's a B4X wish...

Imagine you have a sub that takes as parameter a string or an object.
Inside that sub we want to create a View/Node/Control giving it a meaningfull name, like

B4X:
Sub CreateMap (myMap as string)
Dim (myMap & "Button") as Button
end sub

In this very simplistic example, imagine the user calls the sub using

CreateMap("Cableguy") 'or an Object Name converted to string...

This would create a Button named CableguyButton

In a more real world application, I am thinking of collections and collection arrays, or even arrays of collections!
Instead of creating each Map individually, of instead of creating an ambiguously named Map Array, we could in a single sub create a MAP with a very more meaningful name!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Objects do not have names.
The variables names are not really important.

If you want to create a button and later reference it based on a string then you should use a Map.
B4X:
Sub CreateButton(Name As String)
 Dim b As Button
 b.Initialize("b")
 MyViews.Put(Name, b)
End Sub


Sub GetButton(Name As String) As Button
 Return MyViews(Name)
End Sub
'Usage:
GetButton("Button1").Text = "Asdasd"

Tip: use B4XView from XUI library.
 
Top