function selectQuestion():boolean; //选题
var i,i1,i2,i3,i4,i5,p,p1,s1,s:integer;
var iTemp:integer;
var OldAnswerCount:integer;
var flag:integer;
var IsSelectQuestion:boolean;
var dlgresult:integer;
begin
OptionDlg:=TOKRightDlg.Create(form1);
i2:=0;
i4:=0;
repeat dlgresult:=OptionDlg.ShowModal;
flag:=0;
result:=false;
if dlgresult=mrOK then
begin
setlength(PaperInarray,length(EditArray) div 2);
s:=0;
flag:=0;
try
for i:=0 to length(EditArray) div 2 -1 do
begin
PaperInarray[i,0]:=strtoint(trim(EditArray[2*i].Text));
PaperInarray[i,1]:=strtoint(trim(EditArray[2*i+1].Text));
S:=S+PaperInArray[i,0]*PaperInArray[i,1];
end;
if strtoint(trim(optiondlg.Edit1.Text))<=0 then
if MessageBox(form1.Handle, '对不起,总分应大于零!'+#13+'按确定重新输入,按取消放弃。', '错误', MB_OKCANCEL)=IDOK then
flag:=1
else flag:=2
else
if strtoint(trim(OptionDlg.Edit1.Text))<>s then
if MessageBox(form1.Handle, '对不起,您填入的各题分数总和与总分不符!'+#13+'按确定重新输入,按取消放弃。', '错误', MB_OKCANCEL)=IDOK then
flag:=1
else flag:=2;
except
on EConvertError do
if MessageBox(Form1.Handle, '错误,请确认填入的应是数字!'+#13+'按确定重新输入,按取消放弃。', '错误', MB_OKCANCEL)=IDOK then
flag:=1;
else flag:=2;
end;
if flag=0 then
begin //开始选题
s1:=0;
DM1.StyleQuery1.Close;
DM1.StyleQuery1.Open;
DM1.StyleQuery1.First;
for i:=0 to length(PaperInarray)-1 do
s1:=s1+PaperInArray[i,0];
SetLength(QuestionArray,s1);
Setlength(AnswerArray,0);
for i:=0 to length(PaperInarray)-1 do
begin
dm1.QuestionQuery1.Close;
//DM1.QuestionQuery1.ParamByName('CPoint').AsInteger:=i+1;
DM1.QuestionQuery1.SQL.Clear;
DM1.QuestionQuery1.SQL.Text:='select id,AnswerIDPosition from questiontable where style='
+inttostr(i+1);
DM1.QuestionQuery1.Open;
if PaperInArray[i,0]>dm1.QuestionQuery1.RecordCount then
begin
if MessageBox(Form1.Handle, '对不起,题库中没有足够题目!'+#13+'按确定重新输入,按取消放弃。', '错误', MB_OKCANCEL)=IDOK then
flag:=1
else flag:=2;
break;
end
else
begin
if dm1.StyleQuery1.FieldByName('Title').AsString='选择题'
then IsSelectQuestion:=true
else IsSelectQuestion:=false;
dm1.StyleQuery1.Next;
for i1:=1 to PaperInArray[i,0] do //PaperInArray[i,0]为试卷中i题型题数
begin
repeat
randomize;
dm1.QuestionQuery1.First;
p:=random(dm1.QuestionQuery1.RecordCount);
dm1.QuestionQuery1.MoveBy(p);
setlength(temparray1,length(QuestionArray));
for itemp:=0 to length(QuestionArray)-1 do
tempArray1[itemp]:=QuestionArray[itemp,0];
until Iterant(dm1.QuestionQuery1.FieldByName('ID').AsInteger,TempArray1)<0;
QuestionArray[i2,0]:=dm1.QuestionQuery1.FieldByName('ID').AsInteger;
if IsSelectQuestion then
begin //是选择题
QuestionArray[i2,1]:=length(answerArray);
OldAnswerCount:=QuestionArray[i2,1];
DM1.AnswerQuery1.close;
// DM1.AnswerQuery1.ParamByName('CPoint').AsInteger:=QuestionArray[i2,0];
// showmessage(DM1.AnswerQuery1.sql.Text);
DM1.AnswerQuery1.sql.Clear;
DM1.AnswerQuery1.SQL.Text:='Select * from AnswerTable where OwnerQuestionID='+inttostr(QuestionArray[i2,0]);
DM1.AnswerQuery1.Open;
//if DM1.AnswerQuery1.IsEmpty then
// MessageBox(self.Handle, '对不起,'+strtoint(QuestionArray[k,0])+'号题目没有答案!'+#13+'按OK重新输入,按Cancel放弃。', '错误', MB_OKCANCEL)=IDOK then
for i3:=1 to 4 do
begin
repeat
randomize;
DM1.AnswerQuery1.First;
p1:=random(DM1.AnswerQuery1.RecordCount);
dm1.AnswerQuery1.MoveBy(p1);
setlength(temparray2,length(AnswerArray));
for itemp:=0 to length(AnswerArray)-1 do
tempArray2[itemp]:=AnswerArray[itemp,0];
until Iterant(dm1.answerQuery1.FieldByName('ID').AsInteger,TempArray2)<0;
SetLength(AnswerArray,i4+1);
Answerarray[i4,0]:=dm1.answerQuery1.FieldByName('ID').AsInteger; //id
Answerarray[i4,1]:=dm1.AnswerQuery1.fieldByName('Position').AsInteger; //位置
Answerarray[i4,2]:=0; //不是正确答案
i4:=I4+1;
end;
setlength(temparray3,i4-OldAnswerCount);
for itemp:=oldAnswercount to i4 do
tempArray3[itemp-oldanswercount]:=AnswerArray[itemp,1];
if Iterant(dm1.QuestionQuery1.FieldByName('AnswerIDPosition').AsInteger,TempArray3)<0 then
begin
randomize;
p1:=random(i4-oldAnswerCount); //i4+1-oldAnswerCount 选项数
Answerarray[OldAnswerCount+p1,0]:=dm1.answerQuery1.FieldByName('ID').AsInteger; //id
Answerarray[OldAnswerCount+p1,1]:=p1; //位置不变
Answerarray[oldAnswerCount+p1,2]:=1; //是正确答案
end
else Answerarray[Iterant(dm1.QuestionQuery1.FieldByName('AnswerIDPosition').AsInteger,TempArray3)+oldAnswerCount,2]:=1;
for i5:=oldAnswerCount to i4 do
AnswerArray[i5,1]:=i5-oldAnswercount; //调整Position
end
else //不是选择题
begin
DM1.AnswerQuery1.First;
repeat
SetLength(AnswerArray,i4+1);
Answerarray[i4,0]:=dm1.answerQuery1.FieldByName('ID').AsInteger;
Answerarray[i4,1]:=dm1.AnswerQuery1.FieldByName('position').AsInteger;
Answerarray[i4,2]:=1; //是正确答案
i4:=I4+1;
DM1.AnswerQuery1.Next;
until DM1.AnswerQuery1.Eof;
end;
i2:=i2+1;
end; //
end;
end; result:=true; //所有题都取完。
end;
if flag<>1 then flag:=0;
end;
until flag=0;
end;
这是我的全部伪代码,要调的话还得建数据库,恐怕不好办。
如果能看出什么破绽的话,快发言吧,多谢了!