How to delete all objects in list?

11 views
Skip to first unread message

Kazimir

unread,
May 26, 2010, 9:44:02 PM5/26/10
to Caché, Ensemble, DeepSee
Hello,
I have a class with following method:
Method delete()
{
set current=..Children.GetNext()
while (current'="")
{
do current.delete()
do ..%DeleteId(current.%Id())
set current=..Children.GetNext()

}
set current=..Rows.GetNext()
while(current'="")
{
do current.%DeleteId(current.%Id())
// bug set current=..Rows.GetNext()
}
//code omitted
}
This method is being called when object is being removed, that is why
I don't care about clearing the Rows. Problem is "set
current=..Rows.GetNext()" always return first element in Rows and
current.%DeleteId(...) doesn't work too. I'm confused because in first
case with Children list all is fine.
Can anyone help me?

Regards, Kazimir

Alexander Riemer

unread,
May 28, 2010, 2:50:33 AM5/28/10
to Caché, Ensemble, DeepSee
Hello Kazimir,

your code should look like this:

Method delete()
{
set key=""
        set current=..Children.GetNext(.key)
        while (key'="")
        {
                        do current.delete()
                        do ..%DeleteId(current.%Id())
do ..Children.RemoveAt(key)
                        set current=..Children.GetNext(.key)

        }
set key=""
        set current=..Rows.GetNext(.key)
        while(key'="")
        {
                do current.%DeleteId(current.%Id())
do ..Rows.RemoveAt(key)
set current=..Rows.GetNext(.key)
        }
}

If you use a parent-child relationship and delete the parent object,
you even don't have to delete the children, Caché does it for you.

Regards
Alex

Kazimir

unread,
May 28, 2010, 7:09:05 AM5/28/10
to Caché, Ensemble, DeepSee
Thanks. Simple as always :)
Reply all
Reply to author
Forward
0 new messages