home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Format (Spanish) 3
/
PCF3.iso
/
formula
/
lists.sx_
/
lists.sx
Wrap
Text File
|
1996-04-06
|
4KB
|
134 lines
////////////////////////
// Harrow Software 96
// List examples
////////////////////////////////////////////////
// (1) - Adding objects to a list
// Several object will be created for this example
$my_string = "a string" //a string
my_array = new float[100] //a floating point array
my_structure = new struct //a structure
// A new list will now be created and the objects will
// be placed on the list
my_list = new list
my_list add my_string
my_list add my_array
my_list add my_structure
my_structure.value = 100
my_structure.flag = TRUE
// We can count how many items are on the list using the 'max'
// extension
message "There are ", my_list.max, " objects on the list"
// Now that these objects are on the list, they can be passed
// around using one convenient handle. At some later stage we
// may need to get them off the list. We can get a handle on
// them while they are on the list
my_string = my_list get 0
my_array = my_list get 1
my_structure = my_list get 2
// or we can pop them off the top of the list and leave the
// list empty. Note that the last one added to the list will
// be the first one off
my_structure = my_list pop
my_array = my_list pop
my_string = my_list pop
// if necessary we can make sure that the list is emptry
my_list remove all
////////////////////////////////////////////////
// (2) Lists of lists and object names
// lists are objects too and so a list can be added to another
// list. We can say that a parent list has a handle to a
// child list
my_other_list = new list
my_list add my_other_list
// Objects can be given names. In this case we will assign a
// name as well as a number to an array object and place
// it on our child list
my_object = new float[100]
$my_object.name = "some name"
my_other_list add my_object
// We can then get the object from the list using its name
// rather than its position. In this case we will search the
// parent list for the name of the object. Not only will the
// parent list be searched but also the child list (and its
// children)
my_object = my_list find "some name"
////////////////////////////////////////////////
// (3) List loops
// When you need to look at every object on a list the fastest
// way to do it is with a list loop. First we will create a
// network of lists containing different types of objects.
my_string_list = new list // a new list of strings
my_string_array = new byte[10][32] // a new array of strings
$my_string_array[0] = "zero";"one";"two";"three";"four";"five";"six";"seven";"eight";"nine"
my_string_list add my_string_array // add the array to the list
for n = 0 to my_string_array(0)-1
$my_string = $my_string_array[n] // add every string to the list
my_string_list add my_string
my_struct_list = new list // a new list of structures
for n = 0 to 9
my_structure = new struct // a new structure
$my_structure.name = "struct",n
my_structure.value = n
my_structure.flag = TRUE
my_struct_list add my_structure // add the structure to the list
my_everything_list = new list // make a complete list
my_everything_list add my_string_list // add the other lists
my_everything_list add my_struct_list
// Now we can get these items from the list. First we will
// display the types of items in the base list.
message "Parent list"
the_item = my_everything_list loop n
message $the_item.type
message ""
// Then we can display type of every item in every list
message "All lists"
the_item = my_everything_list loop n mode LIST_TREE
message $the_item.type," - ",n
message ""
// Finally we can get a handle to every item of a certain type
// on the list. In this case we will get the structures.
message "Structures up"
the_item = my_everything_list loop n type "Structure" mode LIST_TREE
message $the_item.name," ",the_item.value," ",the_item.flag
message ""
message "Structures down"
the_item = my_everything_list loop n type "Structure" mode LIST_TREE | LIST_DOWN
message $the_item.name," ",the_item.value," ",the_item.flag
message ""