CurrentElement() -get pointer of current element in save way

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

CurrentElement() -get pointer of current element in save way

Post by Lebostein »

There are some save functions to get pointers:

- FirstElement() - returns the pointer of first element or zero
- NextElement() - returns the pointer of next element or zero
- PreviousElement() - returns the pointer of previous element or zero

I serach a function like that:

- CurrentElement() - returns the pointer of current element or zero

At the moment, the only way to get the pointer of the current element (@list) is not save. You have to use ListIndex() to prevent errors:

Code: Select all

Macro CurrentElement(mypointer, mylist)

  If ListIndex(mylist) = -1: mypointer = 0: Else: mypointer = @mylist: EndIf

EndMacro

NewList test()
CurrentElement(*pointer, test())
Debug *pointer

AddElement(test())
CurrentElement(*pointer, test())
Debug *pointer

ResetList(test())
CurrentElement(*pointer, test())
Debug *pointer