Moving Element from one list to a other
Posted: Wed Jul 10, 2013 4:46 pm
Would be nice to have a native way to move an element from one list to a other. Doing it by hand, is a little bit complicated.
http://www.purebasic.com
https://www.purebasic.fr/english/
Pointers to the listelement are lost in this caseDK_PETER wrote:? What's wrong with CopyStructure()?
Code: Select all
Declare CopyTheElement(*src, *dest)
Structure ELEMENT_DATA
id.i
num.i
var.s
EndStructure
Global NewList List1.ELEMENT_DATA()
Global NewList List2.ELEMENT_DATA()
Procedure CopyTheElement(*src, *dest)
CopyStructure(*src, *dest, ELEMENT_DATA)
EndProcedure
For x = 0 To 100
AddElement(List1())
List1()\id = Random(255,10)
List1()\num = Random(1000,100)
List1()\var = "This is a string " + Str(x)
Next x
SelectElement(List1(),55)
AddElement(List2())
CopyTheElement(@List1(), @List2())
Debug Str(List2()\id)
Debug List2()\var
Code: Select all
ChangeCurrentElement (List1(), *Element)
MoveElement (List1(), #PB_List_Last)
SplitList (List1(), ListTemp())
MergeLists (ListTemp(), List2)
That's a great idea.Josh wrote:There is a way, but you have to create a temporary list and then you have to do this:I think Pb should do this by an easier native way.Code: Select all
ChangeCurrentElement (List1(), *Element) MoveElement (List1(), #PB_List_Last) SplitList (List1(), ListTemp()) MergeLists (ListTemp(), List2)