Android Question List to Array conversion?

b4auser1

Well-Known Member
Licensed User
Longtime User
I created a Sub to convert List to Array. Is there another way to do this ?
B4X:
Private Sub List2Array (a_lstArgs As List) As Object()
    Dim arrArgs(a_lstArgs.Size) As Object
    For i = 0 To arrArgs.Length - 1
        arrArgs(i) = a_lstArgs.Get(i)
    Next
    Return arrArgs
End Sub
 

b4auser1

Well-Known Member
Licensed User
Longtime User
Erel,
I am trying to keep one framework for B4A and B4J, but unfortunetely B4A and B4J have some differences.
F.e. B4A:
B4X:
 ExecQuery2 (Query As String, StringArgs() As String) As android.database.Cursor
B4J:
B4X:
ExecQuery2 (Query As String, Args As List) As ResultSet

So I had to create several wrappers:
B4X:
Sub Process_Globals

    Type B4x_Cursor (cur As Cursor) '<- B4A 
    'Type B4x_Cursor (cur As ResultSet) '<- B4J

End Sub

Private Sub List2Array (a_lstArgs As List) As Object()
    Dim arrArgs(a_lstArgs.Size) As Object
    For i = 0 To arrArgs.Length - 1
        arrArgs(i) = a_lstArgs.Get(i)
    Next
    Return arrArgs
End Sub

Public Sub ExecQuery2 (a_SQL As SQL, a_sStatement As String, a_lstArgs As List, a_sMsgBoxTitle As String) As B4x_Cursor   
'Public Sub ExecQuery2 (a_SQL As SQL, a_sStatement As String, a_lstArgs As List, a_sMsgBoxTitle As String) As ResultSet 'ResultSet <- B4J
'Public Sub ExecQuery2 (a_SQL As SQL, a_sStatement As String, a_lstArgs As List, a_sMsgBoxTitle As String) As Cursor 'Cursor <- B4A   
    Try
        Dim cur As B4x_Cursor
        cur.cur = a_SQL.ExecQuery2(a_sStatement, List2Array(a_lstArgs)) '<-B4A
        'cur.cur = a_SQL.ExecQuery2(a_sStatement, a_lstArgs) '<-B4J
        Return cur
    Catch
'        Log(LastException.Message)
        If a_sMsgBoxTitle <> "" Then
            MsgBoxW.Show(LastException.Message, a_sMsgBoxTitle)
        End If
        Return Null
    End Try
End Sub

If you would eliminate differences just in libs it would really great !
 
Upvote 0
Top