BUG: FOR EACH Fails to Remove All Objects

Last reviewed: November 21, 1997
Article ID: Q176895
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 5.0, 5.0a

SYMPTOMS

When you use FOR EACH in Visual FoxPro version 5.x as a looping mechanism to remove all objects in a container, only half of the objects in the container are removed.

RESOLUTION

Wrap the FOR EACH command with the DO WHILE command. The following sample code is the workaround for the problem illustrated in the Steps to Reproduce Behavior section.

Replace the code in the Click method with the following code:

      DO WHILE Thisform.CommandGroup1.ButtonCount <> 0
      FOR EACH oControl IN Thisform.CommandGroup1.Buttons
      Thisform.CommandGroup1.RemoveObject(oControl.Name)
      ENDFOR
      ENDDO

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new form.

  2. Add a CommandGroup to the form and set the following properties:

          Height = 180
          Width = 96
          ButtonCount = 6
    

  3. Add a second Commandbutton to the form and set the following property:

          Caption = "Click Me"
    

  4. In the Click method of the Commandbutton, type the following code:

          FOR EACH oControl IN Thisform.CommandGroup1.Buttons
          Thisform.CommandGroup1.RemoveObject(oControl.Name)
          ENDFOR
    

  5. Run the form, and click the "Click Me" button.

NOTE: Only three buttons in the CommandGroup are deleted and the other three still show up.


Additional query words: container remove
Keywords : FxprgGeneral vfoxwin
Version : WINDOWS:5.0,5.0a
Platform : WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.