这样可以吗?(Path是操作的文件的路径家文件名,如'd:\test.txt')
type
  MyRecord = Record
    v: String[20];  //记录在文件中的String类型必须要制定长度
end;{$R *.DFM}
procedure W(Path: String);
var
  f: file of MyRecord;
  a: Array of MyRecord;
  i: Integer;
begin
  SetLength(a, 10);
  for i:= Low(a) to High(a) do
    a[i].v:= 'No.' + IntToStr(i) + ' is ' + IntToStr(i);  AssignFile(f, Path);
  ReWrite(f);
  for i:= Low(a) to High(a) do
    Write(f, a[i]);  CloseFile(f);
end;procedure R(Path: String);
var
  f: file of MyRecord;
  t: MyRecord;
  i: Integer;
begin
  AssignFile(f, Path);
  Reset(f);
  while not EOF(f) do
  begin
    Read(f, t);
    Form1.Memo1.Lines.Add(t.v);
  end;
  CloseFile(f);
end;procedure S(Path: String; Index: Integer);
var
  f: File of MyRecord;
  t: MyRecord;
begin
  AssignFile(f, Path);
  Reset(f);
  Seek(f, Index);
  Read(f, t);
  ShowMessage(t.v);
  CloseFile(f);
end;

解决方案 »

  1.   

    seek用于文件的定位,例如一个文件,里面已经有了内容,如果要从指定的地方如10个字节处开始写文件,那么就可以用seek进行定位!write是写入文件。read则是读取。自己耐着性子看书吧。
      

  2.   

    关于文本文件的操作,以上内容都已经过时。一个TSTRINGS足够解决一切
    var
     a:tstrings;
    begin
     a:=tstringlists.create;
     a.loadfromfile('c:\a.txt');
    对STRINGS的操作非常方便,查找、插入都可以实现。最后用SAVETOFILE就是。
    自己看帮助吧。
      

  3.   

    用tstrings时候,文件内容不多时还可以,如果太大,酒会出现问题.
    不过用他排序,还是很好的.