Hi
A wish for enhanced functionality when handling lists. Could something like this be implemented? (Pls. see included code for a practical example of what I have in mind).
Recently I found myself in need of some added functionality for handling lists of items beyond what is currently available as built- in functions in Hollywood 3.x. In effect I needed a linked list where each link knew the link before and the link after in a closed loop (very handy for managing taborders among user controls for one thing). The start of the list would then simply be declared by a pointer to one item in the list that could be changed at any time. Further ther would be a counter for the number of items in the list. Finally there would be a way to store the current list being worked on for use as defaultvalue. Each item in the list has a sublist with a 'previous' and a 'next' value and indexed by the name of the object. These values refers to the indexnames of the actual objects, which are stored in another 'objects' list.
I created a number of functions for managing such lists as follows:
Code: Select all
linklists.new (linklistname$) - this creates a new list
linklist.addlink (id$,oldid$,linklistname$) - adds a link to a list before object(oldid$)
linklist.removelink(id$,linklistname$) - removes a link (and thus references to an object) from the list.
linklist.movelink(id$,targetid$,linklistname$) - moves a link to location just before link identified by targetid$
linklist.swaplinks(id1$,id2$,linklistname$) - swaps location of two links
linklists.getnextlink (id$,linklistname$) - Returns next link after link identified by id$ (or last link by default)
linklists.getpreviouslink(id$,linklistname$) - Returns previouslink before link identified by id$ (or first link by default)
linklists.getlinkcount(linklistname$) - Returns number of links in list.
linklists.setfirstlink(id$,linklistname$) - Sets pointer to first link in the list.
A small example:
Assume you have three objects as in Object={"No1","No2","No3"}
Code: Select all
linklists.new("MyList") This creates a new (empty) list identified by "MyList" and sets the currentlistname$ to "MyList"
linklist.addlink("No2") Adds an entry for object["No2"] in our current list as its last item.
linklist.addlink("No3") Adds another entry at the end.
linklist.addlink("No1","No2") Adds and entry for object["No1"] before the entry for object["No2"] in our current list.
Code: Select all
While linklists.getlinkcount > 0
linklists.removelink() /* Removes the last link in the current list */
Wend
Code: Select all
linklists.getnextlink("no2")
Code: Select all
linklists["MyList"].first$ /* (since 'first$' is the pointer to the first link) */
linklists.getpreviouslink() /* another way of getting the first link using a default */
Code: Select all
linklists["MyList"][first$].prev$ (Remember it is a closed loop so last and first are next to each other)
linklists.getnextlink() /* Another way of getting the last link using a default */