As you know, Map is a kind of list of pairs of data; each pair is composed of a key and a value which can be of any type.
An example that I believe can be useful:
You have a beautiful table SQLite. This table contains some fields:
ID INTEGER Primary Key
Name TEXT
Age INTEGER
Other ... many.
Create a class related to this table:
clsPerson:
Now you could use a Map to store all records (in memory!), filling the Map with data taken from DB, creating an Item for the great class of Informatix CheckList and load the data in item by taking them from the Map.
(I wrote an excessive synthesis; eventually I will post a complete example).
An example that I believe can be useful:
You have a beautiful table SQLite. This table contains some fields:
ID INTEGER Primary Key
Name TEXT
Age INTEGER
Other ... many.
Create a class related to this table:
clsPerson:
B4X:
'Class module - clsPerson
Sub Class_Globals
#Region Properties member variables
Private mID As Int
Private mName As String
Private mAge As Int
#End Region
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(ID As Int, Name As String)
mID = ID
mName = Name
End Sub
#Region + P R O P E R T I E S
' ID
Public Sub setID(ID As Int)
mID = ID
End Sub
Public Sub getID As Int
Return mID
End Sub
' Name
Public Sub setName(Name As String)
mName = Name
End Sub
Public Sub getName As String
Return mName
End Sub
' Age
Public Sub setAge(Age As Int)
mAge = Age
End Sub
Public Sub getAge As Int
Return mAge
End Sub
#End Region
#Region + M E T H O D S
#End Region
Now you could use a Map to store all records (in memory!), filling the Map with data taken from DB, creating an Item for the great class of Informatix CheckList and load the data in item by taking them from the Map.
(I wrote an excessive synthesis; eventually I will post a complete example).
B4X:
Private DB As SQL
' OMISSIS: Open the DB
Private mapPersons As Map : mapPersons.Initialize
Private Query As String = "SELECT * FROM Person"
Private Cur As Cursor
Cur = DB.ExecQuery(Query)
Private ID, Age As Int
Private Name As String
For r = 0 To Cur.RowCount - 1
Cur.Position = r
ID = Cur.GetInt("ID")
Name = Cur.GetString("Name")
Age = Cur.GetInt("Age")
Private Person As clsPerson
Person.Initialize(ID, Name)
Person.Age = Age
mapPersons.Put(ID, Person)
Next
DB.Close
Last edited: