这是怎么会越界?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;
。
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;
。
begin
tempStrList.Append(self.ZHInverseEN(listbox.Items.Strings[count]));--问题处
end;
这是没有问题的
你在这段代码的前面加上这句话 试一下
tempStrList := TStringList.Create(nil);
估计是你的tempStrList没有创建
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;
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的意图在哪
报的错误应该是越界错呀
那在哪越界,谢谢,麻烦了
listbox中没有数据,。
if listbox.count>0 then
for count:=0 to listbox.Count-1 do
begin
tempStrList.Append(self.ZHInverseEN(listbox.Items.Strings[count]));--问题处
end;
。
把这个去掉试下。
你是想把记录逐条写到listbox还是写到tempStrList?
你说出你的想法大家才能帮你
应该listbox项的索引是从0开始,listbox.count-1结束呀
我也用showmessage(count)跟踪过数据呀
也可以显示呀,就是到了最后一顼,就出那个错误。。
郁闷。
谢谢大家的支持呀
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
aa没有符值
数据连接错误,连接了没执行的数据