<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle19
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>I have a freepascal Windows console application that I recently ported over from DOS Turbo Pascal. I am have a small settings file that I write to disk that keeps getting corrupted. It happens only occasionally, but it’s always this one file, no others. Do I need to do something specific to force windows to write the file to disk and not have it in some kind of cache or buffer? I am using the following code to write the file:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> Assign(BitFile,'BitSave.pax');<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> ReWrite(BitFile);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,XADJ:1:8);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,YADJ:1:8);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,ZADJ:1:8);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,WADJ:1:8);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,AADJ:1:8);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,TADJ:1:8);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,VADJ:1:8);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,UADJ:1:8);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(BitFile,CurrentTool);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> WriteLn(Bitfile,P_Value[4]);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'> Close(BitFile); <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>The above only happens when I make a change to one of the settings, and the system is never having any issue at that time, yet upon occasion I will have an error opening the file and when I inspect it, it’s just a long string of [nul]. I am not leaving the file open, I’m assigning it, writing to it, then closing it, so there should be no opportunity for data to be lost. I am having the same issue on about 8 different computers, most of which are running solid state hard drives. It’s always just this one file that is affected, nothing else. No other process ever uses this file, so it must be my freepascal program that is leaving the file in a vulnerable state.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>My understanding was the Close(file); would save the file all the way to disk and flush any buffers that were holding it, but I’m wondering if that was only true for DOS and there is some other windows cache or buffer that also needs to be instructed to flush to truly save the file all the way to disk and close it.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>Thanks for any advice on this<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>James<o:p></o:p></span></p></div></body></html>