procedure TForm1.Button1Click(Sender: TObject);
var
  Flogfile:textfile;
  Slogrec:string;
  Llogrec:Tstringlist;
  i:integer;
  rowitem:tlistitem;
begin
    assignfile(Flogfile,'E:\系统\rizhi1.txt');
  reset(Flogfile);
  try
  begin
    while not eof(Flogfile) do
    begin
      readln(Flogfile,Slogrec);
      Slogrec:=copy(Slogrec,3,length(Slogrec)-4);
      Llogrec:=splitstring(Slogrec,'^');
      rowitem:=self.ListView1.items.add;
      for i:=0 to Llogrec.Count-1 do
      begin
        case strtoint(leftstr(Llogrec[i],1)) of
        1:  rowitem.SubItems.Strings[0]:=copy(Llogrec[i],2,length(Llogrec[i])-1);
        2:  rowitem.SubItems.Strings[1]:=copy(Llogrec[i],2,length(Llogrec[i])-1);
        3:  rowitem.SubItems.Strings[2]:=copy(Llogrec[i],2,length(Llogrec[i])-1);
        4:  rowitem.SubItems.Strings[3]:=copy(Llogrec[i],2,length(Llogrec[i])-1);
        5:  rowitem.SubItems.Strings[4]:=copy(Llogrec[i],2,length(Llogrec[i])-1);
        6:  rowitem.SubItems.Strings[5]:=copy(Llogrec[i],2,length(Llogrec[i])-1);
        end;
      end;
    end;
  end;
  finally
    closefile(Flogfile);
  end;
end;

解决方案 »

  1.   

    rowitem.SubItems.Add(copy(Llogrec[i],2,length(Llogrec[i])-1));
    全部这样改
      

  2.   

    赋值时不能用rowitem.SubItems.Strings[0]
    要用rowitem.SubItems.Addrowitem.SubItems.Strings[0]是用来取值的
      

  3.   

    照corn1的做了,运行没有错误,但是listview是空白的,没有数据显示;
    还有就是我用 2:  rowitem.SubItems.Strings[1]:=copy(Llogrec[i],2,length(Llogrec[i])-1); 
    本意是想将数据插入到第二列,如果用rowitem.SubItems.Add 好像不能实现,该怎么做呢
      

  4.   

    var
      item:TListItem;
    begin
      item := ListView.Items.Add;
      Item.Caption := 'aaaa';
      Item.SubItems.Add('bbb');//第二列
      Item.SubItems.Add('ccc');//第三列
      Item.SubItems.Add('DDD');//第四列
    end;