PRB: ADDOBJECT Gives "A member object...already exists" Error

Last reviewed: November 7, 1996
Article ID: Q158822
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 5.0

SYMPTOMS

Adding an object to a container after removing that object, may result in the following error message:

   A member object with this name already exists

STATUS

This behavior is by design.

MORE INFORMATION

Visual FoxPro does not allow the removal of an object if code for that object is currently executing. Attempts to remove the object are delayed until the object code has completed execution, and Visual FoxPro does not display any warning or errors. This leads users to believe that the object has been removed when it has not been removed. Trying to add the object back into the container causes the "A member object with this name already exists" error because the object was not removed and is still a part of the container.

Steps to Reproduce Behavior

  1. Execute the following code (which instantiates a Form with a CommandButton object):

          PUBLIC oF
          oF = CreateObject('form')
          oF.AddObject('oCont','Cont')
          oF.Show()
    

          DEFINE CLASS Cont AS Container
    
            ADD OBJECT oCmd AS Cmd
            Visible = .t.
          ENDDEFINE
    
          DEFINE CLASS Cmd AS CommandButton
            Top = 50
            Visible=.t.
            PROCEDURE click
              oF.RemoveObject('ocont')     && No error occurs
              oF.AddObject('ocont','cont') && Produces error
            ENDPROC
          ENDDEFINE
    
    

  2. When the Form appears, click on the command button. The "A member object with this name already exists" error message appears.


KBCategory: kbprg kbprb
KBSubcategory: FxprgClassoop
Additional reference words: 5.00 VFoxWin kbdse



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 7, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.