AssignFile(F, SearchPath);
  FileMode   :=   0;  
   Reset(F); //在这个地方,打开文件读取的时候,因为文件正在有其他软件写入,所以我无法读取,   
while not eof(F) do begin
     Readln(F,S);
      sl2.Add(S);
     end;
  CloseFile(F);如何解决??跪谢

解决方案 »

  1.   

    或者 Reset失败就弹出提示,退出咯
      

  2.   

    如果占用的文件正在被写入,你怎么读?所以除非文件是只读打开的,否则你读不到。Reset失败就是读不到了。
      

  3.   

    使用文件流进行读取,打开文件时将打开模式设置为读
    如:
    var
     filestream: TFilestream;
    begin
     filestream:=Tfilestream.create('c:\readme.txt', mOpenRead);
    ....end;
    具体参考delphi helpCreates an instance of TFileStream.Delphi syntax:constructor Create(const FileName: string; Mode: Word); overload;
    constructor Create(const FileName: string; Mode: Word; Rights: Cardinal); overload; DescriptionCall Create to instantiate a file stream for reading from or writing to the named file. Specify the name of the file and the way the file should be opened as parameters.The Mode parameter indicates how the file is to be opened. The Mode parameter consists of an open mode and (possibly) a share mode or抏d together. The open mode must be one of the following values:Value MeaningfmCreate Create a file with the given name. If a file with the given name exists, open the file in write mode.
    fmOpenRead Open the file for reading only.
    fmOpenWrite Open the file for writing only. Writing to the file completely replaces the current contents.
    fmOpenReadWrite Open the file to modify the current contents rather than replace them.The share mode must be one of the following values:Value MeaningfmShareCompat Sharing is compatible with the way FCBs are opened.
    fmShareExclusive Other applications can not open the file for any reason.
    fmShareDenyWrite Other applications can open the file for reading but not for writing.
    fmShareDenyRead Other applications can open the file for writing but not for reading.
    fmShareDenyNone No attempt is made to prevent other applications from reading from or writing to the file.The Rights parameter indicates the permission bits with which to create the file on Linux when Mode is fmCreate. Rights is ignored when used on the Windows platform.If the file can not be opened, Create raises an exception.