有一个txt文件,我想按行读取其中的内容,如何实现?请各位大虾帮忙!

解决方案 »

  1.   

    procedure TForm1.Memo1Change(Sender: TObject);
    begin
      Memo1.Lines.LoadFromFile('C:\Autoexec.bat');
    end;
      

  2.   

    先声明一个变量MyTxt:Textfile;
    再assignfile(Mytxt,'c:\1.txt');
    然后Readln;
      

  3.   

    if not (FileExists(GetNameDir(Application.ExeName)+'111.txt')) then
      begin
        Application.MessageBox('xuanhao.txt文件不存在','提示',MB_OK+MB_ICONSTOP);
        Exit;
      end;
      AssignFile(FileName,GetNameDir(Application.ExeName) + '111.txt');
      Reset(FileName);
      Readln(FileName,Str);
      CloseFile(FileName);
      

  4.   

    var
      a:Tstringlist;
    begin
      a:=Tstringlist.create;
      a.loadfromfile('');
      a.string[i]
      a.free;
    end;
      

  5.   

    var
      F: TextFile;
      s: string;
      
    begin
      //test sFileName is exists?
      if not FileExists(sFileName) then
        Exit;
        
      //Associate File
      AssignFile(F,sFileName);        
      
      //Opens an existing file
      Reset(F);
      
      //First clear the memo
      //Here Memo1 is Global var,and you can use Array 
      //or TMemoryStream var in stead of it.
      if Memo1.lines.count > 0 then  
        Memo1.lines.clear;
        
      //Read data per line
      s := '';
      while (not Eoln(F))  //File not end
      begin
        Readln(F,s);
        Memo1.lines.Add(s);
              
        s := '';
      end;  //end of [while (not Eoln(F))]      
            
      //Close File
      CloseFile(F);
    end;
      

  6.   

    同意  theone_jxm() ( ) 信誉:100
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      F1:TextFile;
      Tmp_Str:String;
    begin
      AssignFile(F1,'c:\yourtxtfile.txt');
      Reset(F1);
      while not Eof(F1) do
      begin
        Readln(F1,Tmp_str);
        ShowMessage(Tmp_Str);
      end;
      CloseFile(F1);
    end;
      

  8.   

    var   F: TextFile;
      S: string;
    begin
      if OpenDialog1.Execute then            { Display Open dialog box }
      begin
        AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
        Reset(F);
        Readln(F, S);                        { Read first line of file }
        Edit1.Text := S;                     { Put string in a TEdit control }
        CloseFile(F);
      end;
    end;