建议用TSTRINGLIST,直接用READFROMFILE

解决方案 »

  1.   

    var
      Line0 : string;
      f: TStringList;
    begin
      f := TStringList.Create;
      try
        f.LoadFromFile('d:\filename.txt');
        Line0 := f.lines[0];
      finally
        f.free;
      end;
    end;
      

  2.   

    刚才写错了,
    Line0 := f.Strings[0];
      

  3.   

    procedure TFrmIME.BitBtn3Click(Sender: TObject);
    var
      S: string;
      F:TexTFile;
    begin
      if OpenDialog1.Execute then
      begin
        AssignFile(F, OpenDialog1.FileName);
        ReSet(F);
        while not Eof(F) do
        begin
          Readln(F, S);
          ShowMessage(S);
        end;  
        CloseFile(F);
      end;
    end;end.
      

  4.   

    其实行简单:
    var 
      Temp:AnsiString;
      MF:TextFile;
    begin    
      AssignFile(MF,'data.dat');
      Reset(MF);
      Readln(MF,temp);
    end;   
    变量temp是从文件DATA.DAT中读取出一行;
      

  5.   

    procedure TFrmIME.BitBtn3Click(Sender: TObject);
    var
      S: string;
      F:TexTFile;
    begin
      if OpenDialog1.Execute then
      begin
        AssignFile(F, OpenDialog1.FileName);
        ReSet(F);
        while not Eof(F) do
        begin
          Readln(F, S);
          ShowMessage(S);
        end;  
        CloseFile(F);
      end;
    end;
      

  6.   

    先写一个名为:a.txt的文本文件,然后再读出来
    procedure TForm1.WrtFileClick(Sender: TObject);
    var
      T:TextFile;
      Path:String;
    begin
      Path:=GetCurrentDir+'\a.txt';
      AssignFile(T,Path);
      ReWrite(T);
      Write(T,'aa');
      WriteLn(T);
      CloseFile(T);
    end;procedure TForm1.OpnFileClick(Sender: TObject);
    var
      T:TextFile;
      Path,Str:String;
    begin
      Path:=GetCurrentDir+'\a.txt';
      AssignFile(T,Path);
      if FileExists(Path) then
        Reset(T)
      else
        Exit;
      Read(T,Str);
      ShowMessage(Str);
      CloseFile(T);
    end;