Using Delete Each within a function

BlitzPlus Forums/BlitzPlus Programming/Using Delete Each within a function

Tomas Khan(Posted 2011) [#1]
I have a function (currently only hypothetical) that creates Type objects, and I want to delete the Type objects I created in the function when it is over. I don't think I should use Delete Each, but I am wondering if I could. This is the scenario:

Suppose I have a Type called "aType". I have created aType objects in the main loop. If I pass an aType object to a function, create an aType object within the function, then call Delete Each aType within the function, what will happen?

The first possibility I considered: Since the function can't access the aType objects created in the main loop, the aType objects that were not passed to the function will not be deleted, but the object passed to the function will be deleted, as will all of the objects in the function. When I return to the main loop: The aType object I passed to the function will now be Null; the other aType objects in main will still be there. I can't access the objects from the function anyway, so the fact that they were deleted doesn't matter in main.

The second possibility: All aType objects will be deleted, regardless of where they are. When I return to the main loop: I won't have any aType objects at all.

This is primarily a technical question (I suspect that it's probably better for me to run a For...Each loop through the aType objects, checking whether I created them in the function or not), but I thought it might be a good idea to ask.


H&K(Posted 2011) [#2]
I dont have BPLus so This is just from general Blitz experience, BUT isnt the list of "Atype" objects GLobal?

That is it doesnt matter where they are created they are on the same list? If so then a delete each wouldnt know which was which and would delete them all.

I wait with bated breath a correct answer ;)

Last edited 2011


Yasha(Posted 2011) [#3]
The second one. The builtin type lists are global.


Tomas Khan(Posted 2011) [#4]
Yeah, I wondered if that might be it. Thanks.


Mahan(Posted 2011) [#5]
I created the Collection Library (CollLib.dll) to handle multiple and local lists of unique types. Using it you can make a local list of type-instances in a function and then delete them when finished, without having to iterate the full global list.

Besides this CollLib can have the same object in several lists or you can work with two (or more) lists containing objects of the same type simultaneously.

http://www.blitzbasic.com/Community/posts.php?topic=86730

Last edited 2011


Adam Novagen(Posted 2011) [#6]
Or you could just add something like:

Type aType
    ;Existing fields
    Field TypeOfThing
End Type


Then use If aType\TypeOfThing = [whatever] Then Delete aType. Basically just use a field to identify what KIND of thing the Type is, so that you can then quickly and easily use/delete those specific Types even while looping through all of 'em.