typemyRecord=record
   Name:String[10];
   Age:SmallInt;
   end;myList: file of myRecord;procedure ReadFromFile(astrFileName:String;aiIndex:Integer;var aRecord:myRecord);
var
  fList:myList;
begin
    AssignFile(fList,astrFileName);
    Reset(fList);
    Seek(aiIndex-1);//记录起始为1。
    Read(fList,aRecord);
    CloseFile(fList);
end;procedure AppendToFile(astrFileName:String;aRecord:myRecord);
var
  fList:myList;
begin
    AssignFile(fList,astrFileName);
    Reset(fList);
    Seek(FileSize(fList));
    Write(fList,aRecord);
    CloseFile(fList);
end;

解决方案 »

  1.   

    var
    ay:array[0..count] of string;
    i:integer;
    tmpstr:string;
    F1:textfile;
    ch:char;
    begin
      assignfile(F1,opendialog1.FileName);
           reset(F1);
           read(F1,ch);
           while ch<>#26 do//#26 is end
           begin
               while ch<>#13 do //#13 行末
               begin
                 if ch=#10 then break; 
                   append;
                   for i:=0 to count-1 do//按照数据库结构存储字段数
                   begin
                       tmpstr:='';
                       while ch<>#9 do
                       begin
                           if ch=#26 then break;
                           tmpstr:=tmpstr+ch;
                           read(F1,ch);
                       end;
                       ay[i]:=tmpstr;
                       read(F1,ch);
                   end;
                   post;
               end;
               read(f1,ch);
          end;
          closefile(F1);
    end;
      

  2.   

    给你三个函数,或许对你有帮助
    例如:
    文本内容:
    a|b|c|d
    e|f|g|h
    i|j|k|l
    strgrid:tstrings;
    strgrid.LoadFromFile(文本名)
    读记录:getfield(strgrid.strings[0],2,"|") 值为 "c"
    写纪录:strgrid.strings[0]:=writefield(strgrid.strings[0],2,"cc");
    文本第一行变为:a|b|cc|d//功能:从字符串中取出字符。
    //参数:s:字符串;idx:字符串中位置;flag:分隔符。
    //返回值:字符串值。
    function getfield(s:string;idx:integer;flag:string='|'):string;
    var
       i,curidx:integer;
    begin
         i:=0;
         curidx:=0;
         result:='';
            while i<length(s) do
              begin
                if s[i]=flag then
                  begin
                    curidx:=curidx+1;
                  end;
                    if idx=curidx then
                      begin
                        result:=result+s[i+1];
                      end;
                i:=i+1;
              end;
        if result<>'' then
          begin
            if result[length(result)]=flag then
              begin
                delete(result,length(result),1);
              end;
          end;
    end;//将字符串变量赋值到字符串的第i个位置
    //参数:s:字符串,i:字符串中位置,value:字符串变量。
    //返回值:字符串值。
    Function WriteField(S:String;i:integer;Value:string):string;
    var
       str:array[0..2048]of char;
    begin
       StrCopy(str,PChar(S));
       WriteRecordField(str,i,PChar(value));
       WriteField:=str;
    end;
    //被 Writefield调用//功能:行记录的某一字段内容
    //参数:buff:行记录,fieldnum:字段编号,rtBuff:字段内容。
    //返回值:布尔值。
    Function WriteRecordField(
    buff:PChar;//行记录
    fieldnum:Integer;//字段编号(字段数=n,编号=0..n-1)
    rtBuff:PChar//字段内容
    ):boolean;
    var
    i,j,k:integer;
            str:array[0..2048] of char;
    begin
            i:=0;
            j:=0;        writeRecordField:=False;        while (j<=fieldnum) do
            begin
                 if j=fieldnum then
                 begin
                      WriteRecordField:=True;                  k:=i;
                      while (buff[i]<>#0) and (buff[i]<>'|') do
                           i:=i+1;                  strcopy(str,@buff[i]);
                      buff[k]:=#0;
                      strcat(buff,rtBuff);
                      strcat(buff,str);
                      j:=j+1;
                 end
                 else
                 begin
                      if  buff[i]='|' then
                          j:=j+1
                      else
                      if buff[i]=#0 then
                      begin
                         buff[i]:='|';
                         buff[i+1]:=#0;
                         j:=j+1
                      end;
                      i:=i+1;
                 end;
            end;end;