B4J Question Simple solution-replace deprecated Map Methods GetKeyAt / GetValueAt

Harris

Expert
Licensed User
Longtime User
B4X:
        For x = 0 To tblFields.Size -1
            Dim var, var1 As String
' must replace .GetValueAt ...
            var  = tblFields.GetValueAt(x)
            var1 = tblFields.GetValueAt(3) ' trk field
            If var = "null" Then
                var = ""
            End If
          
' must replace .GetKeyAt ...
            If tblFields.GetKeyAt(x) = "filename" Then
                ls1.Initialize
....
B4X:

These two methods of a Map object are simple, (invaluable) and very effective.
My projects are littered with them, because that was how I was taught to get keys and their values.

I know the "For Each" replacement required (have implemented sometimes - not so simple) - but that is much more code for every time I use the KeyAt and ValueAt...
I got brain fog right now - so can you smart people supply a simple method I can call to supplement (replace) these deprecated methods (before my app breaks) on the next B4X version update?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
For Each k As String In m.Keys
 Dim v As String = m.Get(k)

Next
1. This is not more complex than using GetKeyAt / GetValueAt.
2. It is cross platform.
3. It will work with all kinds of maps including concurrent maps (such as jServer maps).
4. It will perform better in some cases.
 
Upvote 0
Top