Writing a string to a TFileStream in Delphi 2010

前端 未结 2 1616
不思量自难忘°
不思量自难忘° 2021-02-07 11:27

I have Delphi 2007 code that looks like this:

procedure WriteString(Stream: TFileStream; var SourceBuffer: PChar; s: string);
begin
  StrPCopy(SourceBuffer,s);
          


        
2条回答
  •  [愿得一人]
    2021-02-07 12:03

    Delphi 2010 has a nice solution for this, documented here:

    http://docwiki.embarcadero.com/CodeExamples/en/StreamStrRdWr_%28Delphi%29

    var
      Writer: TStreamWriter;
    ...
    
      { Create a new stream writer directly. }
      Writer := TStreamWriter.Create('MyFile.txt', false, TEncoding.UTF8);
      Writer.Write('Some Text');
    
      { Close and free the writer. }
      Writer.Free();
    

提交回复
热议问题