I have a function whitch creates .xml files with some data inside. Everytime firstly it deletes the old file. Everything works fine except it sometimes gets frozen and the file itself becomes locked. It's size is 0 kb and program can't even delete it. And I have to kill the process, delete the file by myself and then run the program again. Is it possible to kill all the processes of the same program before the begining of a new one? Or at least put some timer on it to make sure it turns off automatically after some time passes by?
Need some ideas, thanks.
fHandle = f_cFile("D:\Data\new_eur\Saskaitos.xml")
if fHandle < 0
**=messagebox("Can't create file!",16,"!!!")
=STRTOFILE("Can't create XML file" + CHR(13) + CHR(10), "d:\Log.txt", 1)
quit
ENDIF
** Header
if fputs(fHandle, '<?xml version="1.0" encoding="windows-1257"?>') < 0
=fclose(fHandle)
=STRTOFILE("Can't write to XML file" + CHR(13) + CHR(10), "d:\Log.txt", 1)
quit
endif
=STRTOFILE(TTOC(dateTIME()) + ": " + "XML ok"+CHR(13)+CHR(10), "d:\LogData.txt", 1)
=fputs(fHandle, "<Accounts>")
enteris = CHR(13)
DO WHILE NOT EOF()
=fputs(fHandle, "<Detali>")
=fputs(fHandle, "<Snr><![CDATA[" + ALLTRIM(Data.dok_nr) + "]]></Snr>" + enteris)
=fputs(fHandle, "<Code_ks><![CDATA[" + ALLTRIM(Data.Code_ks) + "]]></Code_ks>" + enteris)
=fputs(fHandle, "<Sdata>" + ALLTRIM(Data.dok_data) + "</Sdata>" + enteris)
=fputs(fHandle, "<Term>" + ALLTRIM(Duomenys.Terminas) + "</Term>" + enteris)
=fputs(fHandle, "<Manager><![CDATA[" + ALLTRIM(Data.Code_ms) + "]]></Manager>" + enteris)
IF Data.val_poz = 0
=fputs(fHandle, "<MokSuma>" + ALLTRIM(STR(Duomenys.SumaMok, 12, 2)) + "</MokSuma>" + enteris)
=fputs(fHandle, "<ApSuma>" + ALLTRIM(STR(Duomenys.ApSuma, 12, 2)) + "</ApSuma>" + enteris)
ELSE
=fputs(fHandle, "<MokSuma>" + ALLTRIM(STR(Duomenys.SumaVal, 12, 2)) + "</MokSuma>" + enteris)
=fputs(fHandle, "<ApSuma>" + ALLTRIM(STR(Duomenys.ApVal, 12, 2)) + "</ApSuma>" + enteris)
ENDIF
=fputs(fHandle, "</Detali>")
skip
ENDDO
fputs(fHandle, "</Accounts>")
=fclose(fHandle)
Now this is the code which puts xml data into the file. At some point it freezes and the next time program starts it is still using the same file.
Function f_cFile:
FUNCTION f_cFile
PARAMETERS fName
fHandle = fcreate(fName)
IF fHandle < 0
IF FILE(fName,1)
DELETE FILE fName
IF FILE(fName,1)
=STRTOFILE("Can't delete old file: " + fName + CHR(13) + CHR(10), " d:\Log.txt", 1)
ELSE
fHandle = fcreate(fName)
ENDIF
ENDIF
ENDIF
RETURN fHandle
ENDFUNC