How Can I Efficiently Read The FIrst Few Lines of Many Files in Delphi

后端 未结 5 2064
清歌不尽
清歌不尽 2020-12-15 12:43

I have a \"Find Files\" function in my program that will find text files with the .ged suffix that my program reads. I display the found results in an explorer-like window t

5条回答
  •  自闭症患者
    2020-12-15 13:05

    Okay, I deleted my first answer. Using Remy's first suggestion above, I tried again with built-in stuff. What I don't like here is that you have to create and free two objects. I think I would make my own class to wrap this up:

    var
      fs:TFileStream;
      tr:TTextReader;
      filename:String;
    begin
      filename :=  'c:\temp\textFileUtf8.txt';
      fs := TFileStream.Create(filename, fmOpenRead);
      tr := TStreamReader.Create(fs);
      try
          Memo1.Lines.Add( tr.ReadLine );
    
      finally
        tr.Free;
        fs.Free;
      end;   
    end;
    

    If anybody is interested in what I had here before, it had the problem of not working with unicode files.

提交回复
热议问题