Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deleting a FXP
Message
From
04/01/2018 11:28:26
 
 
To
04/01/2018 09:40:42
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01656909
Message ID:
01656947
Views:
1158
>>>I'm back with another question.
>>>
>>>I am creating a PRG file dynamically, that contains a Class definition.
>>>
>>>
>>>lcAll "define class ..."
>>>THIS.Filename = ADDBS(SYS(2023))+CFG_PREFIX+SYS(3)+".prg"
>>>
>>>STRTOFILE(lcAll,THIS.Filename,0)
>>>ret = NEWOBJECT(THIS.Section, THIS.Filename)
>>>
>>>ERASE (THIS.Filename)
>>>*** Error occurs here, "File cannot be closed because outstanding references exist."
>>>ERASE (forceext( THIS.Filename, "fxp") )
>>>
>>>
>>>I am creating optimized classes, and have difficulty on the clean up procedure.
>>>
>>>I create a temporary PRG containing a DEFINE CLASS block. At the top of PRG is a RETURN CREATEOBJECT(...) statement. When the PRG is called the object is returned. The temporary PRG is deleted, but the FXP is still in use. How to close before ERASE.
>>>
>>>The object finished being initiated. I believed that NewObject() opened the library, created the object, then closed the library. Therefore bypassing the SET PROCEDURE call. The FXP should be freed, ya. But until a CLEAR ALL seems to be issued, the file is locked by VFP.
>>>
>>>Any suggestion?
>>
>>Use CREATEOBJECT() instead of NEWOBJECT() to guarantee that clearing the class closes the associated program files.
>>
>>
>>#DEFINE CFG_PREFIX	"abc"
>>
>>LOCAL SourceCode AS String
>>LOCAL Filename AS String
>>LOCAL Instance AS Object
>>LOCAL Section AS String
>>LOCAL ARRAY FilesInDisk(1)
>>
>>m.Section = "XYZ"
>>
>>TEXT TO m.SourceCode NOSHOW TEXTMERGE
>>DEFINE CLASS <<m.Section>> AS Custom
>>	FUNCTION Operation (Op1 AS Number, Op2 AS Number)
>>		RETURN m.Op1 * m.Op2
>>	ENDFUNC
>>ENDDEFINE
>>ENDTEXT
>>
>>m.Filename = ADDBS(SYS(2023)) + CFG_PREFIX + SYS(3) + ".prg"
>>
>>STRTOFILE(m.SourceCode, m.Filename, 0)
>>SET PROCEDURE TO (m.Filename) ADDITIVE
>>
>>m.Instance = CREATEOBJECT(m.Section)
>>? m.Instance.Operation(2, 3)
>>
>>m.Instance = .NULL.
>>RELEASE m.Instance
>>
>>CLEAR CLASS (m.Section)
>>
>>ERASE (m.Filename)
>>ERASE (FORCEEXT(m.FileName, "fxp") )
>>
>>MESSAGEBOX(TEXTMERGE("Files in disk like <<FORCEEXT(m.Filename, '*')>>: <<ADIR(m.FilesInDisk, FORCEEXT(m.Filename, '*'))>>"))
>>
>
>After looking at your example it has became clear that the issue is that the object is still associated with the FXP. Until the object is released, the FXP can not be deleted.
>I have instituted a garbage collection to remove any unused FXP files from the Temp folder (I marker each file name with a prefix to identify.)
>This All about preventing clutter and blot.


Been there, done that... for me least amount of maintainance was to create a factory class, which creates a process-singular temp dir and directs all such activity there - including fixing path when actually working. On release factory object cleans up directory. No need for bookkeeping or mangling file names ;-)

>Personally, I am looking for a solution that does involve writing ANY thing to disk before processing. The ExecScript does not seem to provide the solution; returning a NULL on a CreateObject, when the object was created.

You are working against vfp inner structure - advise against it, find a least odious band-aid solution ;-)

>Well, the search continues. I have too much time on my hands.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform