title: Writing a string to a TFileStream in Delphi 2010
body: <p>I have Delphi 2007 code that looks like this:</p>
  
  <pre><code>procedure WriteString(Stream: TFileStream; var SourceBuffer: PChar; s: string);
  begin
    StrPCopy(SourceBuffer,s);
    Stream.Write(SourceBuffer[0], StrLen(SourceBuffer));
  end;
  </code></pre>
  
  <p>I call it like this:</p>
  
  <pre><code>var
    SourceBuffer : PChar;
    MyFile: TFileStream;
  
  ....
  
  SourceBuffer := StrAlloc(1024);
  MyFile := TFileStream.Create('MyFile.txt',fmCreate);
  WriteString(MyFile,SourceBuffer,'Some Text');
  ....
  </code></pre>
  
  <p>This worked in Delphi 2007, but it gives me a lot of junk characters in Delphi 2010.  I know this is due to unicode compliance issues, but I am not sure how to address the issue.</p>
  
  <p>Here is what I've tried so far:</p>
  
  <ul>
  <li><p>Change the data type of
  SourceBuffer(and also the parameter
  expected by WideString) to PWideChar</p></li>
  <li><p>Every one of the <a href="https://stackoverflow.com/questions/1354092">suggestions listed 
  here</a></p></li>
  </ul>
  
  <p>What am I doing wrong?</p>