请问如何读取一个文本文中的行数???

解决方案 »

  1.   

    tstringlist.loadfromfile();
    tstringlist.count;
      

  2.   

    var
      t :TextFile;
      i :integer;
    begin
      assignfile(t, 'c:\1.txt');
      Reset(t);
      while not EOF(t) do
        inc(i);
    ShowMessage(Inttostr(i));
    end;
      

  3.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      FileName: string;  function Method1: Integer;
      begin
        with TStringList.Create do
        try
          LoadFromFile(FileName);
          Result := Count;
        finally
          Free
        end;
      end;  function Method2: Integer;    procedure ProcLine(P: PChar; Count: Integer);
        begin
          while Count > 0 do
          begin
            if P^ = #10 then Inc(Result);
            Inc(P);
            Dec(Count);
          end;
        end;  var
        Buffer: PChar;
        RetLen, Count: Integer;
      begin
        Result := 0;
        with TFileStream.Create(FileName, fmShareDenyNone) do
        try
          Count := Size;
          GetMem(Buffer, 102400);
          try
            while Count > 0 do
            begin
              RetLen := Read(Buffer^, 102400);
              ProcLine(Buffer, RetLen);
              Dec(Count, RetLen);
            end;
          finally
            FreeMem(Buffer);
          end;
        finally
          Free;
        end;
      end;var
      S1, S2: string;
      Count1, Count2: Integer;
      StartTime, EndTime: DWORD;
    begin
      FileName := 'c:\temp\a.txt';
      StartTime := GetTickCount;
      Count1 := Method1;
      EndTime := GetTickCount;
      S1 := Format('Time1: %f, Count: %d', [(EndTime - StartTime)/1000, Count1]);
      StartTime := GetTickCount;
      Count2 := Method2;
      EndTime := GetTickCount;
      S2 := Format('Time2: %f, Count: %d', [(EndTime - StartTime)/1000, Count2]);
      Caption := S1 + ';' + S2;
    end;
      

  4.   

    TStringList.LoadFrom(FileName)
    TStringList.Count
      

  5.   

    请问TStringList.LoadFrom(FileName)
    中的TStringList是什么组件????????
      

  6.   

    TStringList.LoadFrom(FileName)
    TStringList.Count
    这个速度快
      

  7.   

    还请问高手TStringList.LoadFrom(FileName)
    中的TStringList是什么组件????????
    以及如何将该文本一行一行的读出来??????多谢了,我是刚接触delphi,请详细解答,再多谢了!!!!!!!!
      

  8.   

    我这边测试的是用16M数据的文本,结果是:Time1: 0.81, Count: 712701;Time2: 0.08, Count: 712700
      

  9.   

    不是组件,是类来的,如果你刚学Delphi就还是找些书看吧,如果你学过其它的语言,你应该知道每个语言都封装了很的功能类,这些需要积累,我也说不清。而且还不如按F1来的快,虽是英文的,但想要学好编程,不管是C++/delphi都好,看英文是必不可少的。
      

  10.   

    copy_paste(木石三) 给你的测试的那个源码给我好吗?????发到我的email:[email protected]中,万分感谢!!!!!!!!