seek用来把文件指针移动到指定的地方,比如你想读文件偏移量为100(从文件的头上算起)的地方,用
seek(f, 100);
这样你下次用Read的时候就直接从偏移量为100的地方读了。

解决方案 »

  1.   

    另外TFileStream的Seek用法也差不多,但他们不但可以指定从文件头上计算偏移,也可以从当前的地方,或是文件尾部开始。
      

  2.   

    那么文件的偏移量指什么??? 
    size;
    有记录就是记录的的size;
      

  3.   

    那各位大侠帮我们看看这段吧
    t.xh:=edit1.Text;
     t.xm:=edit2.Text;
     t.yw:=strtoint(edit3.text);
     t.wy:=strtoint(edit4.text);
     t.sx:=strtoint(edit5.text);
     assignfile(f,'d:\文件.dat');
     reset(f);
     size:=filesize(f);
     seek(f,size);
     listbox1.Items.Clear;
     seek(f,0);
     while not eof(f) do
     begin
     read(f,t);
     listbox1.Items.Add(t.xh+' '+t.xm+' '+inttostr(t.yw)+' '+inttostr(t.wy)+' '+inttostr(t.sx));
     end;
     closefile(f);
      

  4.   

    文件的偏移量其实是指文件指针的偏移量,也就是对文件头的"距离",比如,偏移量为100,就是离文件的头部有100个字节的“距离”。文件指针通过他来定位读写位置。普通的读写操作同时会自动移动文件指针到当前读写操作结束的地方。像你给出的例子,
    reset用来复位文件指针,这时的偏移量为0,也就是在文件的头上。
    然后size:=filesize(f); 得到文件的大小
    seek(f,size); 把文件指针移到文件尾部
    listbox1.Items.Clear; 好像跟主题没啥关联
    seek(f,0); 有移到了文件头上!? 这段代码谁写的?
    下面这段把把文件里的数据读进……好像有问题
    while not eof(f) do 
    begin 
    read(f,t); 
    listbox1.Items.Add(t.xh+' '+t.xm+' '+inttostr(t.yw)+' '+inttostr(t.wy)+' '+inttostr(t.sx)); 
    end;