我定义了:f:system.textFile;如何移动文件指针,一行一行的将f 中的内容读出

解决方案 »

  1.   

    Reads a line of text from a file.UnitSystemCategorytext file routinesprocedure Readln([ var F: Text; ] V1 [, V2, ...,Vn ]);DescriptionThe Readln procedure reads a line of text and then skips to the next line of the file.Readln(F) with no parameters causes the current file position to advance to the beginning of the next line if there is one; otherwise, it goes to the end of the file.When an application is compiled as a console application (using the Generate console application checkbox on the Linker page of the Project|Options dialog, or a -cc command line switch with the command-line compiler), Delphi automatically associates the Input and Output files with the application's console window. For non-console applications, any attempt to read from Input or write to Output will generate an I/O error.Note: {$I+} handles run-time errors using exceptions.  When using {$I-}, use IOResult to check for I/O errors.
      

  2.   

    textFile没有文件指针,但它有ReadLn方法一行一行读
    var
     myFile:TextFile;
     str1:string;
    begin
     try
      AssignFile(myFile,'d:\test01.txt');
      Reset(myFile);
      ReadLn(myFile,str1); //如果再次调用ReadLn,会读出下一行
      Memo1.Text:=str1;
     finally
      CloseFile(myFile);
     end;
    end;其他的文件类型,可以用seek()定位文件指针,但对于seek(i)的位移不一样。
    file of byte是移动i个字节,而纪录文件是移动i个纪录。
      

  3.   

    再多一句嘴,其实使用文本文件textfile,如果不是很大的话。
    可以用StringList.LoadFormFile()一次把它全部读出来。
    var
     myList:Strings;
    begin
     myList:=StringList.Create();
     try
      myList.LoadFromFile('d:\test01.txt');
      ...
     finally
      myList.Free;
     end;
    end;myList.Strings[0] 就是第一行,以此类推;myList.Count就是行数
    注意使用完了后,要将其free掉。如果你使用Memo控件显示文本文件的内容,直接Memo1.Lines.LoadFormFile('d:\test01.txt');
      

  4.   

    readline 指针自动向后跳的啊