procedure TForm1.N7Click(Sender: TObject);
var
  txt:string;//变量txt用来存储读取的数据
  txtstr:string;//变量txtstr用来存储文本文件的内容
  txtstring:string;//显示在Data中的每一行
  I: integer;
  n: integer;
     //文本中字符串长度
  column:integer;//Data区共有几行
  count:array [0..5000] of integer; //字符串中'S'的位置
begin
  data.Items.Clear;
     //数据区清除
  txtstr:='';
           //初始化为空串
  column:=0;
            //初始化为0行
  if open.Execute then//使用Execute命令来显示打开对话框
    label2.Caption :=open.FileName;//显示选中文件名及路径
  if fileexists(label2.Caption )then//测试指定文件是否存在
  begin
    assignfile(txtfile,label2.Caption );
    reset(txtfile);
           //打开文件
    while not eof(txtfile) do //当文件没有结束时执行循环
    begin
      readln(txtfile,txt);
    //读取文件
      txtstr:=txtstr+txt;
    end;
    n :=length(txtstr);
       //字符串长度
    for i:=0 to n do
    begin
      if txtstr[i]='S' then
   //字符串中有多少个'S'就有多少行
      begin
        count[column]:=i;
     //字符串中'S'的位置
        column:=column+1;
     //有几行字符串
      end;
    end;
    for i:=0 to column-1 do
   //第0行到最后第二行
    begin
      txtstring:=copy(txtstr,count[i],(count[i+1]-count[i]));
  //起始位置:字符'S'的位置
      data.Items.Add(txtstring);
        //取长度:后面一个'S'的位置-前面一个'S'的位置
    end;
    txtstring:=copy(txtstr,count[column-1],n-count[column-1]+1);
    data.Items.Add(txtstring);
    line:=data.Items.Count;
    edit2.Text:=inttostr(line);
    closefile(txtfile);
   //关闭文件
  end
  else
    showmessage('文件不存在,请重新选择!');
end;