procedure TForm1.BitBtn1Click(Sender: TObject);
var count1,k:integer;
count_select:integer;
begin
with query2 do //清空备用题库
begin
close;
sql.Clear;
sql.add('delete from 备用题库');
execsql;
end;
query1.Close;
query1.SQL.Clear;
query1.sql.Add('select * from 题库');
query1.execsql;
query1.Active:=true;
count1:=query1.recordcount;
if count1<strtoint(trim(edit1.Text)) then
begin
showmessage('对不起,题库内题目不足,不能出题');
query1.Active:=false;
exit;
end;
count_select:=0; //已抽题数目
while (count_select<strtoint(trim(edit1.Text))) do //当已抽题数目 少于 设定抽题数目时
begin
k:=random(count1); //确定随机数
query1.First;
query1.MoveBy(k); //题目可重复
edit2.text:=query1.fieldbyname('题号').asstring;
query1.Close; //将所抽题目插入备用题库
query1.SQL.Clear;
query1.SQL.Add('insert into 备用题库 select * from 辅机题库 where 题号=:th');
query1.Params[0].Asstring:=trim(edit2.text);
query1.execsql;
query1.Active:=false;
count_select:=count_select+1;
end;
query1.Active:=false;
end;
运行后,点击BitBtn1出现错误 list index out of bounds (0)
哪里出问题了啊,怎样才能避免啊!多谢
list index out of bounds (0) 问题