ilan Expert Licensed User Longtime User Oct 19, 2021 #1 i would like this to work without declaring the object newlist B4X: Copy newlist.As(List).AddAll(l) Log(newlist.Size) code that is needed now B4X: Copy 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
i would like this to work without declaring the object newlist B4X: Copy newlist.As(List).AddAll(l) Log(newlist.Size) code that is needed now B4X: Copy 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 Oct 19, 2021 #2 Unless you need to later add or remove elements: Code: Copy Dim newlist As List = Array("aa", "bb") In other cases, you can add a sub that creates the object: Code: Copy 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: Code: Copy newlist.As(List).AddAll(l) Last edited: Oct 19, 2021 Upvote 0
Unless you need to later add or remove elements: Code: Copy Dim newlist As List = Array("aa", "bb") In other cases, you can add a sub that creates the object: Code: Copy 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: Code: Copy newlist.As(List).AddAll(l)
ilan Expert Licensed User Longtime User Oct 19, 2021 #3 Erel said: This code cannot work: [cod]e newlist.As(List).AddAll(l) [/code] Click to expand... 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
Erel said: This code cannot work: [cod]e newlist.As(List).AddAll(l) [/code] Click to expand... 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.
ilan Expert Licensed User Longtime User Oct 19, 2021 #4 B4X: Copy 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
B4X: Copy 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!!
Erel B4X founder Staff member Licensed User Longtime User Oct 19, 2021 #5 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: Code: Copy Dim newlist As List = Array("aa", "bb") Upvote 0
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: Code: Copy Dim newlist As List = Array("aa", "bb")
ilan Expert Licensed User Longtime User Oct 19, 2021 #6 Erel said: 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: Code: Copy Dim newlist As List = Array("aa", "bb") Click to expand... 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: Copy Dim newlist As List = AsNew(List).AddAll(oldlist) Last edited: Oct 19, 2021 Upvote 0
Erel said: 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: Code: Copy Dim newlist As List = Array("aa", "bb") Click to expand... 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: Copy Dim newlist As List = AsNew(List).AddAll(oldlist)