B4J Question [BANano] [SOLVED] How to handle Type Lists AddAll?

Mashiane

Expert
Licensed User
Longtime User
Ola

In a class module I have defined a type.

B4X:
Type StylesObj (font As String, lineWidth As Double, lineColor As List)
    Public styles As StylesObj

On the class Initialize method the type is initializes

B4X:
styles.Initialize
    styles.font = ""
    styles.linewidth = 0
    styles.lineColor.Initialize

Now I create an instance of this class and call it.

B4X:
Dim tblA as MyClass
tblA.Initialize
tblA.styles.font = "Meta"
tblA.styles.lineWidth = 0.55

This works well so far.

However, as soon as I execute this call..

B4X:
tblA.styles.lineColor.AddAll(Array As Int (44, 62, 80))

Im getting a

B4X:
ReferenceError: _linecolor is not defined

This however works well, though longer

B4X:
tblA.styles.lineColor.Add(44)
    tblA.styles.lineColor.Add(62)
    tblA.styles.lineColor.Add(80)

What am I doing wrong..
 

alwaysbusy

Expert
Licensed User
Longtime User
This statement is to complex for the transpiler because of old browser support (IE11). Old Browsers do not support the spread (...) function and there is no PolyFill for it possible. I will give new Browsers priority in the future more and more, because those old browsers will eventually disappear anyway.

So temporary solution:
B4X:
Dim lineColor as List = tblA.styles.lineColor
lineColor.AddAll(Array as Int(44, 62, 80)

Future version of BANano this will not be needed FOR MODERN BROWSERS. If one wants to support the old browsers, it will still be needed and one will have to write this code like this:
B4X:
If BANano.OLDBROWSER Then
     Dim lineColor As List = tblA.styles.lineColor
     lineColor.AddAll(Array As Int (44, 62, 80))
Else
     tblA.styles.lineColor.AddAll(Array As Int (44, 62, 80))
End If

Alwaysbusy
 
Upvote 0
Top