Deleting twice:
Clearly, deleting a dynamic object twice is a bad idea. But when your
code becomes complex, and you need to be able to delete an object from
different places, in different cases, you can end up in this situation.
The random part here is coming from your code (was it deleted before
or not). The error itself appears immediately when you try to delete
an object already deleted.
{AmazonLinks}
The solution is in that case quite simple: test if the object exists before
deleting it. To do that, you need to create a procedure or method in which
you trap an exception occurring when you do an illegal operation on a
non existing object, like setting it in dynamic object pointer...
Of course, it would be better to always know that
an object exists or not, but we all leave in the real world, don't we?