B4J Question Difference between object and no type in list loops

rgarnett1955

Active Member
Licensed User
Longtime User
Hi

Can anyone explain the difference between using and object or number type for enumerating through lists. When should I use Object and when a number type.

Difference between Object and Double:
    For Each item() As Object In bList
        Dim pt As Int
        Dim delta As Double
        Dim xValue As Double
        
        
    For Each item() As Double In bList
        Dim pt As Int
        Dim delta As Double
        Dim xValue As Double

Thankyou
Rob
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
I might not have understood your question, but the objects in the list are going to be whatever objects you used to build the list.

For example ...
B4X:
Sub Process_Globals
    Type position (x As Int, y As Int)
End Sub

Public Sub Createposition (x As Int, y As Int) As position
    Dim t1 As position
    t1.Initialize
    t1.x = x
    t1.y = y
    Return t1
End Sub

Sub Example
    Dim x, y As Int
    Dim locations As List
    locations.Initialize
    locations.Add(Createposition(1000, 2000))
    locations.Add(Createposition(2000,3000))
    locations.Add(Createposition(3000,4000))
    
'    ...
        
    For Each p As position In locations
        x = p.x
        y = p.y
'   ...
    Next
End Sub

Of course this is not the only way that you can use For Each but it a common way. If the list contains objects of mixed types then this would not work, of course, but your implication that the only two possibilities are Objects or Numbers is not correct.
 
Upvote 0
Top