title: TStreamWriter (Auto)Flush does not?
body: <p>Despite what is said in <a href="https://stackoverflow.com/questions/13306752/text-file-writing-performances-in-delphi">Text File Writing performances in Delphi</a> (comments under Ken White's answer), I see the TStreamWriter <strong>not</strong> flushing with the following code:</p>
  
  <pre><code>procedure TFrmAddEvents.LogEvent(AEvent: TcxSchedulerEvent);
  begin
     if not Assigned(FStreamWriter) then
     begin
        FStreamWriter := TStreamWriter.Create(TFileStream.Create(ChangeFileExt(ParamStr(0),'.log'),fmCreate or fmOpenRead));
        FStreamWriter.AutoFlush := true;
     end;
     FStreamWriter.WriteLine(TcxEventDescription(AEvent));
     // Even this has no effect:
     FStreamWriter.Flush;
  end;
  </code></pre>
  
  <p>Even after executing the</p>
  
  <pre><code>if Assigned(FStreamWriter) then FStreamWriter.Free;    
  </code></pre>
  
  <p>in FormClose, the file is still 0 bytes.<br />
  When the program has finished executing, the file is 600+ kB.</p>
  
  <ul>
  <li>FStreamWriter is a form property of type TStreamWriter.</li>
  <li>Creating with <code>fmCreate or fmOpenWrite</code> makes no difference.</li>
  <li>TcxEventDescription does give a valid return string > 500 bytes containing CRLFs.</li>
  <li>As you can see I don't do anything with Encoding, all default Unicode stuff.</li>
  <li>I'm running from the Delphi XE2 IDE or as a standalone executable.</li>
  <li>32 bit app under Win7 64bit</li>
  </ul>
  
  <p>What can be going on and how to fix?</p>
  
  <p>[Edited 7. Jan 2014]</p>
  
  <p>Updated code after Uwe's answer; still does not work:</p>
  
  <pre><code>procedure TFrmAddEvents.LogEvent(AEvent: TcxSchedulerEvent);
  var lName: string;
  begin
     lName := ChangeFileExt(ParamStr(0),'.log');
     if not Assigned(FStreamWriter) then
     begin
        FStreamWriter := TStreamWriter.Create(lName); // Or TStreamWriter.Create(lName,true);
        FStreamWriter.AutoFlush := true;
     end;
     FStreamWriter.WriteLine(TcxEventDescription(AEvent));
     // Next does not help either:
     FStreamWriter.Flush;
  end;
  </code></pre>
  
  <p>Until I call FStreamWriter.Free the file remains 0 bytes.</p>