Hi people
I've used the map collection storing "Type Object" values many times without issue and then hit a problem yesterday trying to store(put) a Type object into a B4XOrderedMap. It also fails with a standard Map... Hence I suspect a dumbass programming error
So I declare a type, dim a type object, and then use a for loop to put data into the type object and then store(put) into a B4xOrderedmap or standard map
If I use the type object it (possibly) puts only the last Type object created, If I try and store a string it works fine ?!
Code below, Simple Project using (B4a Core 9.00, B4xCollections 1.05) which simply logs output from starter service.
Apologies for using up your time, but I have been "tearing my hair out" since yesterday to get my head round this. I suspect I may have to hang my head in embarrassment ?
Thanks in advance
All code in Starter service..
Log gives..
I've used the map collection storing "Type Object" values many times without issue and then hit a problem yesterday trying to store(put) a Type object into a B4XOrderedMap. It also fails with a standard Map... Hence I suspect a dumbass programming error
So I declare a type, dim a type object, and then use a for loop to put data into the type object and then store(put) into a B4xOrderedmap or standard map
If I use the type object it (possibly) puts only the last Type object created, If I try and store a string it works fine ?!
Code below, Simple Project using (B4a Core 9.00, B4xCollections 1.05) which simply logs output from starter service.
Apologies for using up your time, but I have been "tearing my hair out" since yesterday to get my head round this. I suspect I may have to hang my head in embarrassment ?
Thanks in advance
All code in Starter service..
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type tData1(tdID As Int,tdCity As String,tdMonth As Int)
B4X:
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
Dim td1 As tData1
td1.Initialize
Dim omData1 As B4XOrderedMap = B4XCollections.CreateOrderedMap()
For i = 0 To 12
Log("icount = " & i)
td1.tdID = i
td1.tdCity = "City" & i
td1.tdMonth = i
Log("put data for " & i & " td id " & td1.tdID)
omData1.Put(i,td1 )
' omData1.Put(i,"test" & i ) ' This successfully stores and with loop below logs "omdata 1 test1" "omdata 1 test2" etc
' td1.Initialize ' this stores ID's of 0 ?
Next
Log("mdata1 size is " & omData1.Size)
For Each c As Int In omData1.Keys
Log("omdata " & c & " " & omData1.Get(c))
Next
Log gives..
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
icount = 0
put data for 0 td id 0
icount = 1
put data for 1 td id 1
icount = 2
put data for 2 td id 2
icount = 3
put data for 3 td id 3
icount = 4
put data for 4 td id 4
icount = 5
put data for 5 td id 5
icount = 6
put data for 6 td id 6
icount = 7
put data for 7 td id 7
icount = 8
put data for 8 td id 8
icount = 9
put data for 9 td id 9
icount = 10
put data for 10 td id 10
icount = 11
put data for 11 td id 11
icount = 12
put data for 12 td id 12
omdata1 size is 13
omdata 0 [IsInitialized=true, tdCity=City12, tdID=12
, tdMonth=12]
omdata 1 [IsInitialized=true, tdCity=City12, tdID=12
, tdMonth=12]
omdata 2 [IsInitialized=true, tdCity=City12, tdID=12
, tdMonth=12]
omdata 3 [IsInitialized=true, tdCity=City12, tdID=12
, tdMonth=12]
etc, etc