Found an issue in SpiderBasic ? Please report it here !
User avatar
Peter
 
Posts: 689
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080

ChangeCurrentElement() does not work as expected

by Peter Sun Feb 16, 2020 6:28 pm

Hello,

ChangeCurrentElement() does not work as expected.

Code from Help:
Code: Select all
NewList myList()

AddElement(myList())
myList() = 100

AddElement(myList())
myList() = 200
*element = @myList()

AddElement(myList())
myList() = 300

Debug myList()                             ; Displays 300 (last element)
ChangeCurrentElement(myList(), *element)   ; Restore list position
Debug myList()                             ; Displays 200

ForEach myList()
  If @myList() = *element
    Debug "element: " + myList()           ; Displays "element: 200"
  EndIf
Next


SpiderBasic-Output:
300
undefined
element: 200


PureBasic-Output:
300
200
element: 200
MarkOtt
 
Posts: 14
Joined: Thu Sep 14, 2017 12:59 pm

Re: ChangeCurrentElement() does not work as expected

by MarkOtt Wed Feb 19, 2020 11:50 am

Fortunately I was only using Structured Lists until now, puh ...
... Structured List are working.

I think the problem is the @ which delivers the value of an unstructured list entry, instead of the address/object.

Code: Select all
Structure MyStruct
    long.l
EndStructure

NewList myList.MyStruct()

AddElement(myList())
myList()\long = 100

AddElement(myList())
myList()\long = 200
*element = @myList()      ; does not work with unstructured list

AddElement(myList())
myList()\long = 300

Debug myList()\long                             ; Displays 300 (last element)
ChangeCurrentElement(myList(), *element)        ; Restore list position
Debug myList()\long                             ; Displays 200

ForEach myList()
  If @myList() = *element
    Debug "element: " + myList()\long           ; Displays "element: 200"
  EndIf
Next


Regards, Markus
Return to Bugs Reports

Who is online

Users browsing this forum: No registered users and 1 guest