声明变量
var
  f:TextFile;系统提示如下信息:
[Pascal Error] Unit2.pas(1): Unable to invoke Code Completion due to errors in source code请高手指点如何使用TextFile

解决方案 »

  1.   

    读:
    procedure TForm1.Button1Click(Sender: TObject);
    var MyFile:TextFile;
        s:string;
    begin
        try
            AssignFile(MyFile,'d:\a.txt');
            Reset(MyFile);
            Memo1.Clear;
            while not Eof(MyFile) do
            begin
                 ReadLn(MyFile,s);
                 Memo1.Lines.Add(s);
            end;    finally
            CloseFile(MyFile);
        end;
    end;
      

  2.   

    Reset是以只读的方式打开文件,如果文件不存在将出错。append(写的方式打开)不覆盖原文,原文不存在将出错。Rewrite(写的方式打开)覆盖原文,文件不存在将创建,
    procedure TForm1.Button1Click(Sender: TObject);
    var MyFile:TextFile;
        s:string;
    begin
        try
            AssignFile(MyFile,'d:\a.txt');
            Append(MyFile); //或用ReWrite(MyFile),append是不覆盖原文,原文不存在将出错,Rewrite是覆盖原文,文件不存在将创建,
            s:='write textfile';
            WriteLn(MyFile,s);
        finally
            CloseFile(MyFile);
        end;
    end;
      

  3.   

    [Pascal Error] Unit2.pas(1): Unable to invoke Code Completion due to errors in source code出现这个提示是您的代码的其他位置有错误,请检查其他的地方。