PRB: Deleting VB Control Doesn't DeIete Its Code from Memory
ID: Q73808
|
The information in this article applies to:
-
Microsoft Visual Basic programming system for Windows, versions 1.0, 2.0, 3.0
SYMPTOMS
When you delete a control in the Visual Basic environment, the code that
you wrote for that control is not deleted, but is instead moved to the
Object: (General) area for code.
Some programmers may not realize that these detached (unused) procedures
still exist and consume memory. The detached code is available for calling,
copying, or reuse. For example, when you add a control that shares the same
name as a detached procedure, the detached event procedure reassociates
with that control.
RESOLUTION
If you want to delete both the control and its associated code, you need to
manually select and delete the code in each event procedure for that
control in addition to deleting the control itself.
STATUS
This behavior is by design.
MORE INFORMATION
The following example demonstrates that your code goes into the Object:
(General) area after you delete the associated control (or object):
- From the File menu, choose New Project.
- Double-click a command button from the Toolbox to put a Command1 button
on your form.
- Double-click the Command1 button to bring up the code window for the
Command1_Click event procedure.
- Enter the following code inside the Command1_Click procedure:
Sub Command1_Click()
Print "Hello"
End Sub
- Press the F5 key to run the code. Click the Command1 button to see the
text "Hello" display on Form1 in the upper left corner. From the Run
menu, choose End to stop the program.
- Click the Command1 button on Form1 to set the focus there and either
press the DELETE key or choose the Delete command from the Edit menu.
This deletes the Command1 button from the form.
At this point, some programmers may incorrectly assume that the code
associated with the Command1 button was also deleted. Actually, the code
associated with any deleted object is automatically moved into the
Object: (general) area of the Code window for that form. You can find
the detached procedures in the Code window by choosing (general) from
the Object: box, and choosing the procedures from the Proc: box. (Click
the DOWN arrow symbol on the right of the Object: and Proc: boxes to see
your choices.)
Additional query words:
2.00 3.00
Keywords :
Version :
Platform :
Issue type :