Android Question auto declare inline variable/object

ilan

Expert
Licensed User
Longtime User
i would like this to work without declaring the object newlist

B4X:
    newlist.As(List).AddAll(l)
    Log(newlist.Size)

code that is needed now

B4X:
    Dim newlist As List
    newlist.Initialize
    newlist.AddAll(l)
  Log(newlist.Size)

inside subs it should not be to difficult to implement it right?
no need for a global object.

can this be done?

thanx
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Unless you need to later add or remove elements:
B4X:
Dim newlist As List = Array("aa", "bb")

In other cases, you can add a sub that creates the object:
B4X:
Public Sub CreateMyType (Field1 As Int) As MyType 'the IDE can auto-generate such subs for you
 Dim m As MyType
 m.Initialize
 m.Field1 = Field1
 Return m
End Sub

Dim m As MyType = CreateMyType("Asdasd")

This code cannot work:
B4X:
newlist.As(List).AddAll(l)
 
Last edited:
Upvote 0

ilan

Expert
Licensed User
Longtime User
This code cannot work:
[cod]e
newlist.As(List).AddAll(l)
[/code]

Sorry i was not clear enough. Its a WISH ?

i know its not possible now but why?
inside a sub it should not be difficult to implement right erel?

i wanted to copy a list in my last example i did and i find it to long for b4x.

making it shorter with the new b4x feature would be great.

EDIT: how to you call this new chaining feature in b4x? just asking to know how to address it correct.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
B4X:
newlist.As(List).AddAll(l)

this snippet should return already a declared list named newlist with all items added from list "l"
ITS A WISH!!
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
It cannot be implemented unless you are talking specifically about lists. Even in that case it will cause many delicate issues.

If you are talking about lists then there is already a simpler solution:
B4X:
Dim newlist As List = Array("aa", "bb")

yes this solution is good to create a new list but not to copy 1 list to another.
if i want to copy 1 list to a second list i will need to initialize a new list and copy all items in list 1.
anyway, thanks for your answer. i understand that its not a simple task :)

have a nice day!

EDIT: how about this:
B4X:
Dim newlist As List = AsNew(List).AddAll(oldlist)
 
Last edited:
Upvote 0
Top