>Hi Everyone!
>It seems like I still don't understand how this thing works. It simple when we have an array like Example says, but if I want to use form's collection like Objects or Controls.
>For example I want to Remove All objects on a form, I was trying to do something like:
>
>FOR EACH oControl IN ThisForm.Controls
>ThisForm.RemoveObject(oControl.Name)
>ENDIF
>Of course it's not working and I'm not suprised, but it's very interesting how this thing suppoused to be to get it work.
>Thanks!
Valentin,
FOR EACH will work fine in situations where you do NOT change the contents of the collection or array you are processing. To accomplish your goal it would be better to do it this way;
FOR lnCnt = 1 TO THISFORM.ControlCount
THISFORNM.RemoveObj( THISFORM.Controls(1) )
ENDFOR
Notice that the code iun the loop is always removing item 1, that is because once the first control is removed the second becomes 1 and the third becomes 2, so if you increment the control you are removing you will be skipping them. Another approach that works is;
FOR lnCnt = THISFORM.ControlCount TO 1 STEP -1
THISFORNM.RemoveObj( THISFORM.Controls(lnCnt) )
ENDFOR
This removes the last control first and so on back to the first.