用DBGrid,AdoQuery,Access数据库
当DBGrid选中了多行后,处理选中的多条记录时出错。代码如下: with dbgList.DataSource.DataSet do
for i:=0 to dbgList.SelectedRows.Count-1 do
begin
GotoBook(pointer(dbgList.SelectedRows.Items[i]));
.......
end;
end;当第二次执行到GotoBook(pointer(dbgList.SelectedRows.Items[i]))时,报错:Project xxxx raised exception class EStringListError with message 'List index out of bounds(1)'.Process stopped. Use Step or Run to continue.什么原因会引起这样的错误呢?我查了dbgList.SelectedRows.Count,确实是等于2的(选中两条记录)。可第二条记录就无法获取。有什么别的方法可以获取DB选中的多条记录吗?
当DBGrid选中了多行后,处理选中的多条记录时出错。代码如下: with dbgList.DataSource.DataSet do
for i:=0 to dbgList.SelectedRows.Count-1 do
begin
GotoBook(pointer(dbgList.SelectedRows.Items[i]));
.......
end;
end;当第二次执行到GotoBook(pointer(dbgList.SelectedRows.Items[i]))时,报错:Project xxxx raised exception class EStringListError with message 'List index out of bounds(1)'.Process stopped. Use Step or Run to continue.什么原因会引起这样的错误呢?我查了dbgList.SelectedRows.Count,确实是等于2的(选中两条记录)。可第二条记录就无法获取。有什么别的方法可以获取DB选中的多条记录吗?
var
I:Integer ;
BookList:TBookList ;
Book:TBookStr ; Book:=Table1.Book ;
try
BookList:=dbgList.SelectedRows ;
for I;=0 to BookList.Count-1 do
begin
Table1.Book:= BookList[I] ;
......
end ;
finally
Table1.Book:=Book ;
end ;