I'm working on a project where I have a some lists, the items of which need to be frequently replaced by other items inside a procedure where an argument specifies which list is to have its items replaced. However I have found it impossible to do this.
I have created a project called ReplaceList as an example to illustrate my situation.
These are the elements on the project's screen:
The three buttons at the bottom are ListPickers which show the contents of the lists used in the project. The contents of the ListPickers can be updated using the Refresh button. They are also automatically updated when initializing the program and when restoring values using the Restart button.
The project starts with two lists: empty_list, which is initially empty (and is supposed to remain so), and full_list, which starts with three items and has to be replaced by other three items using the top buttons. The two buttons at the top activate the procedures called replace1 and replace2.
The procedure replace1 is supposed to clear the list given to it as an argument (which will always be full_list), called list here; check whether or not list has been successfully cleared, registering the result in the Label1 at the top, and add to it the three new items to add using the add procedure (which just uses the add items to list function to add three items). After this, it adds the items of list to the list ListPicker (that is, the ListPicker labeled list, not a list named ListPicker, hence the italics), which should end up having the same content as the full_list ListPicker. However, when I activate this procedure by pressing the Replace1 button, the full_list remains unchanged, although the list ListPicker does show the desired outcome.
The procedure repalce2 tries to clear list by setting it to the contents of empty_list, which is at first empty. Then, as does the replace1 procedure, it adds the items by using the add procedure and adds the items of list to the list ListPicker. When I activate this procedure by pressing the Replace2 button, the results are the same as with the Replace1 button (full_list unchanged but list ListPicker with the desired outcome of full_list), except that empty_list, which should always remain empty, is also changed to the desired outcome of full_list.
This is the code used in this project:
I have reached the conclusion that, somehow, when I use the set list to block, it doesn't replace the contents of list, equivalent to the argument of the procedure (full_list), to the argument of the block (create empty list in replace1 and get empty_list in repalce2), but instead makes it equivalent to the argument of the block, so that when I modify the contents of list in replace1, instead of modifying the contents of full_list it modifies the contents of empty_list.
In essence, the following equivalence would be the case:
So I think I know what causes the problem, but I haven't the slightest idea how to fix it. I would very much appreciate some insights on why this happens and how it could be fixed.



