谁能帮我看看这段代码 就是看看他是怎样循环的 谢谢啦 菜鸟帮帮我啊

jinghaijingtian 2010-05-27 10:52:30
while choosenumber<>0 do

begin

query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select tno from ti_choose') ;
if ListBox2.Count>=1 then
begin
for mm:=1 to 9 do
begin
if TF[mm]='t' then
begin
query1.SQL.Add(' where tno not like '''+inttostr(mm)+'%''');
break;
end;
end;
if listBox2.Count>1 then
begin

for mm:=1 to 9 do
if TF[mm]='t' then
begin

query1.SQL.Add(' and tno not like '''+inttostr(mm)+'%''');
end;
end;
end;
query1.Open;
query1.First;


while not query1.Eof do
begin
hade:=false;
if i=1 then
begin

thao[i]:=((Query1.FieldValues['tno']) div 10);
end
else
if i>1 then
begin

for j:=i-1 downto 1 do
begin

if thao[j]=((Query1.FieldValues['tno']) div 10) then
begin
t:=true ;
break;
end
else
t:=false;
end;


if not t then
begin
thao[i]:=((Query1.FieldValues['tno']) div 10);
t:=false;
end;
end;

query1.Next;

if not t then
i:=i+1;
end;

temp:=random(i-1)+1;
r:=thao[temp];

q:=random(9)+1;
ran:=r*10+q;


for m:=1 to 800 do havetake[m]:=0;
for m:=1 to 800 do
begin
if havetake[m]=ran then
begin
showmessage('chongfu');
hade:=true;
break;
end;
end;
if not hade then
begin
for m:=0 to 800 do
if havetake[m]=0 then
begin
havetake[m]:=ran;
break;
end;

query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select tigan,xa,xb,xc,xd,answer,difficulty from ti_choose where tno=:no');
query1.ParamByName('no').Value:=ran;

query1.Open;

if choosenumber<>0 then
begin


if query1.RecordCount<>0 then


begin

n:= strtoint(query1.FieldByName('difficulty').AsString);
if diff[n] <>0 then
begin

tt:=tt+1;

memo1.Text:=memo1.Text+inttostr(tt)+'、'+query1.fieldbyname('tigan').AsString+#13#10;
memo1.Text:=memo1.Text+query1.fieldbyname('xa').AsString+#13#10;
memo1.Text:=memo1.Text+query1.fieldbyname('xb').AsString+#13#10;
memo1.Text:=memo1.Text+query1.fieldbyname('xc').AsString+#13#10;
memo1.Text:=memo1.Text+query1.fieldbyname('xd').AsString+#13#10;
autoanswerform.Memo1.Text:=autoanswerform.Memo1.Text+inttostr(tt)+'、'+query1.fieldbyname('answer').AsString+#13#10;
choosenumber:=choosenumber-1;
n:=n-1;
end;


end;
end;

end;

end;
progressbar1.Position:=progressbar1.Position+c;
...全文
96 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinghaijingtian 2010-05-28
  • 打赏
  • 举报
回复
谢谢啦 我终于看懂了
zhuoguihu 2010-05-27
  • 打赏
  • 举报
回复
太长,不看,帮顶
hongss 2010-05-27
  • 打赏
  • 举报
回复
不需要看懂SQL啊,只要看看if,for就可以了
jinghaijingtian 2010-05-27
  • 打赏
  • 举报
回复
帮我注释一下 我加分 我也不懂sql语句 看着费劲啊
varick_zhong 2010-05-27
  • 打赏
  • 举报
回复
断点跟踪一下,马上就了解了啊流程
jinghaijingtian 2010-05-27
  • 打赏
  • 举报
回复
它是随机选题 可是怎么确定的呢?
varick_zhong 2010-05-27
  • 打赏
  • 举报
回复
这个循环是基础的嘛,哪有问题?
yktd26 2010-05-27
  • 打赏
  • 举报
回复
temp := random(i - 1) + 1;
r := thao[temp];

q := random(9) + 1;
ran := r * 10 + q;

看来你这些题目是不是是个为一组??
取值时都除以了10,所以这块想把随机做的均匀一些,首先每十个一组的找出组号,
temp := random(i - 1) + 1;
r := thao[temp];

然后再在这十个中随机挑选一个
q := random(9) + 1;
ran := r * 10 + q;
jinghaijingtian 2010-05-27
  • 打赏
  • 举报
回复
是啊 就是那个算法 重要。。。
SS_LO 2010-05-27
  • 打赏
  • 举报
回复

while choosenumber <> 0 do

begin

query1.Close;
query1.SQL.Clear;
query1.SQL.Add('select tno from ti_choose'); // 查询所有题号
if ListBox2.Count >= 1 then // 估计题号添加到了LBX
begin
for mm := 1 to 9 do
begin
if TF[mm] = 't' then
begin
// 此时sql--> select tno from ti_choose where tno not like '1%'
// 添加数据过滤条件 1
query1.SQL.Add(' where tno not like ''' + inttostr(mm) + '%''');
break;
end;
end;
if ListBox2.Count > 1 then
begin
for mm := 1 to 9 do
if TF[mm] = 't' then
begin
// 此时sql--> select tno from ti_choose where tno not like '1%' and and tno not like '2%'
// 添加数据过滤条件 2
query1.SQL.Add(' and tno not like ''' + inttostr(mm) + '%''');
end;
end;
end;
query1.Open; // 执行sql查询数据
query1.First; // RecNo第一条数据

while not query1.Eof do // 遍历数据集
begin
hade := false;
if i = 1 then
begin
thao[i] := ((query1.FieldValues['tno']) div 10); // 第一题? 存入题号
end
else if i > 1 then
begin

for j := i - 1 downto 1 do
begin

if thao[j] = ((query1.FieldValues['tno']) div 10) then
begin
t := true;
break;
end
else
t := false;
end;

if not t then
begin
thao[i] := ((query1.FieldValues['tno']) div 10);
t := false;
end;
end;

query1.Next;

if not t then
i := i + 1;
end;
// 选题(一种算法不懂)
temp := random(i - 1) + 1;
r := thao[temp];

q := random(9) + 1;
ran := r * 10 + q;

for m := 1 to 800 do
havetake[m] := 0;
for m := 1 to 800 do
begin
if havetake[m] = ran then
begin
showmessage('chongfu');
hade := true;
break;
end;
end;
if not hade then
begin
for m := 0 to 800 do
if havetake[m] = 0 then
begin
havetake[m] := ran;
break;
end;

query1.Close;
query1.SQL.Clear;
query1.SQL.Add(
'select tigan,xa,xb,xc,xd,answer,difficulty from ti_choose where tno=:no'
);
query1.ParamByName('no').Value := ran;

query1.Open;

if choosenumber <> 0 then
begin

if query1.RecordCount <> 0 then

begin

n := strtoint(query1.FieldByName('difficulty').AsString);
if diff[n] <> 0 then
begin

tt := tt + 1;

memo1.Text := memo1.Text + inttostr(tt) + '、 ' + query1.FieldByName
('tigan').AsString + #13#10;
memo1.Text := memo1.Text + query1.FieldByName('xa').AsString + #13#10;
memo1.Text := memo1.Text + query1.FieldByName('xb').AsString + #13#10;
memo1.Text := memo1.Text + query1.FieldByName('xc').AsString + #13#10;
memo1.Text := memo1.Text + query1.FieldByName('xd').AsString + #13#10;
autoanswerform.memo1.Text := autoanswerform.memo1.Text + inttostr(tt)
+ '、 ' + query1.FieldByName('answer').AsString + #13#10;
choosenumber := choosenumber - 1;
n := n - 1;
end;

end;
end;

end;

end;


不懂这种随机算法,我懂点的都注释了,不知道对不对

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧