这是怎么会越界?function TForm1.ZHInverseEN(zhStr: String): String;
var
tempStr:String;
count :integer;
begin
  with DM do
  begin
    ADOQuery2.Close;
    ADOQuery2.SQL.Clear;
    ADOQuery2.SQL.Add('select FIELD_DBNAME from TB0002_FIELD_INDEX where FIELD_TITLE=:aa');
    ADOQuery2.Parameters.Items[0].Value:=zhStr;
    ADOQuery2.Open;
    ADOQUery2.First;
    while not ADOQuery2.Eof do
    begin
    tempStr:=  ADOQuery2.Fields.Fields[0].Value;
    result:= tempStr;
    ADOQuery2.Next;
    end; 
  end;
end;。

 for count:=0 to listbox.Count-1 do
     begin
      tempStrList.Append(self.ZHInverseEN(listbox.Items.Strings[count]));--问题处
    end;

解决方案 »

  1.   

     for count:=0 to listbox.Count-1 do
         begin
          tempStrList.Append(self.ZHInverseEN(listbox.Items.Strings[count]));--问题处
        end;
    这是没有问题的
    你在这段代码的前面加上这句话 试一下
    tempStrList := TStringList.Create(nil);
    估计是你的tempStrList没有创建
      

  2.   


    function TForm1.getQueryStrList(listbox: TListBox):TStringList;
    var
       tempStrList:TStringList;
       count:integer;
    begin
     tempStrList := TStringList.Create();--我也有create();好象没有你说的create(nil)方法
      for count:=0 to listbox.Count-1 do
       begin
          tempStrList.Append(self.ZHInverseEN(listbox.Items.Strings[count]));
       end;
       result:=tempStrList;
    end;
      

  3.   

        ADOQUery2.First;
        while not ADOQuery2.Eof do
        begin
        tempStr:=  ADOQuery2.Fields.Fields[0].Value;
        result:= tempStr;
        ADOQuery2.Next;
        end;这里没啥意义,没断点还有
    for count:=0 to listbox.Count-1 do
       begin
          tempStrList.Append(self.ZHInverseEN(listbox.Items.Strings[count]));
       end;
       result:=tempStrList;不要用Append,用add,不知你用append的意图在哪
      

  4.   

    我想问问题出在哪里,append不就是在TStringList追加记录?
    报的错误应该是越界错呀
    那在哪越界,谢谢,麻烦了
      

  5.   

    貌似都不知道listbox是出自何处呢。
      

  6.   

    调试下看count为多少的时候报错
      

  7.   


    listbox中没有数据,。

    if listbox.count>0 then
     for count:=0 to listbox.Count-1 do
         begin
          tempStrList.Append(self.ZHInverseEN(listbox.Items.Strings[count]));--问题处
        end;
      

  8.   

    ADOQUery2.First;
    把这个去掉试下。
      

  9.   

    tempStrList.Append(self.ZHInverseEN(listbox.Items.Strings[count]));--没有什么意义
    你是想把记录逐条写到listbox还是写到tempStrList?
    你说出你的想法大家才能帮你
      

  10.   

    我就是你说的意思难道append()方法不对?
    应该listbox项的索引是从0开始,listbox.count-1结束呀
    我也用showmessage(count)跟踪过数据呀
    也可以显示呀,就是到了最后一顼,就出那个错误。。
    郁闷。
    谢谢大家的支持呀
      

  11.   

    procedure TStringList.InsertObject(Index: Integer; const S: string;
      AObject: TObject);
    begin
      if Sorted then Error(@SSortedListError, 0);
      if (Index < 0) or (Index > FCount) then Error(@SListIndexError Index);
      InsertItem(Index, S, AObject);
    end;
    @SListIndexError =List index out of bounds (%d)就是说你插入的索引当大于或者等于Tstringlist对象里的函数就会出现这个错误。
    自己排错下。我一般用ADD
      

  12.   

    ADOQuery2.SQL.Add('select FIELD_DBNAME from TB0002_FIELD_INDEX where FIELD_TITLE=:aa');
    aa没有符值
    数据连接错误,连接了没执行的数据