delphi 小程序
〔label1〕+〔label2〕=〔edit1〕〔label3〕
另外还有一个button1,edit2.
要求在button1被按下时,label1,label2产生1000以内的任意数,当在edit1中输入正确答案时,〔label3〕立即显示:正确,错误则无提示,并在edit2中统计答对题数.
参考答案:可以定义一个全局变量用来记录正确的数目,并在窗体创建时赋初始值:
procedure TForm1.FormCreate(Sender: TObject);
begin
i := 0;
end;
//随机生成数:
procedure TForm1.Button1Click(Sender: TObject);
var z,j : integer;
begin
Randomize;
j := random(1000);
z := random(1000);
label1.Caption := inttostr(j);
label2.Caption := inttostr(z);
end;
//当按下enter键时判断答案是否正确:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
begin
if edit1.Text =inttostr(strtoint(label1.Caption) + strtoint(label2.Caption)) then
begin
label3.Caption :='タ絋';
i := i+1;
edit2.Text := inttostr(i);
end
else
label3.Caption := '';
end;
end;