Page 1 of 1

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

Posted: Thu Jun 05, 2014 9:10 am
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