logical issue with lists and removing them
Posted: Wed Mar 30, 2011 5:09 am
The following code should delete an element and all child elements. It works fine if I don't reset the list each time I add an element (I reset it as I want new elements up front). However, when I reset the list and add an element, when it goes to delete it won't delete the requested ID, just the child ID. Any ideas why this is happening? I think I just don't understand something...
Code: Select all
Structure object
id.l
parent.l
EndStructure
Global NewList objects.object()
ResetList(objects())
AddElement(objects())
objects()\id = 1
objects()\parent = 0
ResetList(objects())
AddElement(objects())
objects()\id = 2
objects()\parent = 1
ResetList(objects())
AddElement(objects())
objects()\id = 3
objects()\parent = 2
Procedure delete_object(id.l)
ForEach objects()
If objects()\id = id
DeleteElement(objects())
ElseIf objects()\parent = id
delete_object(objects()\id)
EndIf
Next
EndProcedure
delete_object(2)
ForEach objects()
Debug "ID: " + Str(objects()\id) + " :: Parent: " + Str(objects()\parent)
Next