Bug? B4XTable overachieving

emexes

Expert
Licensed User
Longtime User
B4X:
Dim data As List
data.Initialize
data.Add(Array("First",  2,   DateUtils.SetDate(1969, 7, 20)))
data.Add(Array("Second", 3.4, DateUtils.SetDate(1978, 6,  5)))
data.Add(Array("Third",  5,   DateUtils.SetDate(2001, 9, 11)))
data.Add(Array("Fourth", 6.7, DateUtils.SetDate(2025, 8 , 1)))
B4XTable1.SetData(data)
data.Add(Array("Fifth",  8,   DateUtils.SetDate(1971, 1, 11)))
data.Add(Array("Sixth",  9.0, DateUtils.SetDate(1972, 2, 22)))
B4XTable1.SetData(data)

"9 out of 6" ?

Feels like it'd be an easy fix to make the count reasonable. I like that .SetData is cumulative, so ideally would become "9 out of 10" rather than "6 out of 6"

 
Last edited:

emexes

Expert
Licensed User
Longtime User
If you are doing a lot of different B4XTable-of-SQL-tables then it'd be fairly straightforward to have a single general routine that takes a list of fields (columns), adds them to a specified B4XTable and then populates the B4XTable from a specified SQL table.

It'd look something like:
B4X:
Dim Columns() As Object = array( _
    Array("Name",     ColumnTypeText,    "FirstName"), _
    Array("Age",      ColumnTypeNumeric, "Age"),       _
    Array("Location", ColumnTypeText,    "City")       _
)

'create B4XTable columns Name, Age, Location and load from FirstName, Age, City columns of SQL table Students
LoadB4XTableFromSQLTable(B4XTable1, Columns, SQL1, "Students")
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
SetData is asynchronous. If you want to call it multiple times then you should wait for it to complete:
B4X:
data.Initialize
    data.Add(Array("First",  2,   DateUtils.SetDate(1969, 7, 20)))
    data.Add(Array("Second", 3.4, DateUtils.SetDate(1978, 6,  5)))
    data.Add(Array("Third",  5,   DateUtils.SetDate(2001, 9, 11)))
    data.Add(Array("Fourth", 6.7, DateUtils.SetDate(2025, 8 , 1)))
    Wait For (B4XTable1.SetData(data)) Complete (unused As Boolean)
    data.Add(Array("Fifth",  8,   DateUtils.SetDate(1971, 1, 11)))
    data.Add(Array("Sixth",  9.0, DateUtils.SetDate(1972, 2, 22)))
    B4XTable1.SetData(data)
 

emexes

Expert
Licensed User
Longtime User
SetData is asynchronous. If you want to call it multiple times then you should wait for it to complete:

Same result even if I wait for it to complete.

Same result after then doing a .Refresh

Similar incongruent result after then visibly scrolling down one element, but now it says "2 to 10 out of 6"

Same result after then visibly scrolling back to top of list, ie now it is back to "1 to 9 out of 6"

No, hang on a moment... if I also Wait after the intermediate .SetData, then it works correctly (if "correct" is defined as replacing previous B4XTable data).

So I revise my bug report to:

if you have had two .SetData's in action at one time, then the record count does not match the actual number of records.

Ie the "out of" indicates 6 records, but the table looks to contain 10 separate records.

Also just realised I'm still on B4J 10.00 and maybe this is something that's fixed in a later version.
 
Last edited:

emexes

Expert
Licensed User
Longtime User
calling SetData without waiting for it to complete

True, waiting avoids the issue. Thank you.
Lol my broader mistake here was thinking that a better response to a minefield is to clear it rather than signpost it.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…