Microsoft KB Archive/299491

= FIX: Program Execution Stops With Outstanding Class References =

Article ID: 299491

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition

-



This article was previously published under Q299491



SYMPTOMS
Program A runs program B. Program B instantiates a programmatically defined class, then exits. If program A attempts to COMPILE program B, the COMPILE command fails and program execution stops, but no error is given in Visual FoxPro (VFP) 5.0 or 6.0 when this occurs.



STATUS
This problem was corrected in Visual FoxPro version 7.0 for Windows.

In VFP 7.0, the following error message (error 1184) is given:

File cannot be closed because outstanding references exist.



Steps to Reproduce Behavior
  In VFP 5.0 or 6.0, paste the following code in a new program: CLEAR LOCAL lcOldConsole, lcOldSafety lcOldConsole = SET(&quot;CONSOLE&quot;) lcOldSafety = SET(&quot;SAFETY&quot;) SET CONSOLE OFF SET SAFETY OFF

SET TEXTMERGE TO &quot;MyTestProg.prg&quot; TEXT LOCAL loMyClass, lnRetVal loMyClass = CREATEOBJECT(&quot;MyClass&quot;) lnRetVal = loMyClass.TstProc RELEASE loMyClass RETURN lnRetVal

DEFINE CLASS MyClass as Custom PROCEDURE TstProc RETURN 33 ENDPROC ENDDEFINE ENDTEXT SET TEXTMERGE TO SET CONSOLE &lcOldConsole SET SAFETY &lcOldSafety

COMPILE MyTestProg.prg

SET PROCEDURE TO MyTestProg.prg ? SET(&quot;PROCEDURE&quot;) ? &quot;Result: &quot;, MyTestProg

RELEASE PROCEDURE MyTestProg.prg COMPILE MyTestProg.prg
 * !* Program ends here if MyClass class is not cleared. There is no error given in VFP6.
 * !* CLEAR CLASS MyClass && Uncomment for VFP5/6 workaround.

? &quot;This is the last line of code. It ran!&quot;  Save and run this code (the program name is unimportant).

When the code runs in VFP 5.0 and 6.0, the output to the screen includes the current PROCEDURE setting and &quot;Result: 33&quot; (that is, the return value from MyTestProg.prg). The final line of code (&quot;This is the last line...&quot;) is not printed to _SCREEN. This is because an outstanding reference to MyClass exists, so that the COMPILE MyTestProg.prg line does not run successfully. The program exits without error and you may notice the message &quot;Do Canceled&quot; displayed on the status bar.

In VFP7, when this code is run as-is, a new error message (error 1184) is given on the &quot;COMPILE...&quot; line.

Uncomment the line that reads &quot;Clear Class MyClass&quot; to work around this in VFP 5.0, 6.0, and 7.0 and allow the COMPILE command to complete.

Keywords: kbbug kbfix kboop kbcodesnippet kbvfp700fix KB299491

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.