unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; var flag:integer; var n1: Cardinal;
type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; first: TEdit; second: TEdit; result: TEdit; btn_begin: TButton; btn_judge: TButton; lab: TLabel; Label3: TLabel; Label4: TLabel; lab_true: TLabel; lab_false: TLabel; lab_totel: TLabel; procedure btn_beginClick(Sender: TObject); procedure btn_judgeClick(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn_beginClick(Sender: TObject); var f,s:integer;begin n1 := GetTickCount; //get soft run time randomize; // let random initialize f := 10+random(90); // build a number from (0,100] s := 10+random(90); //the same with up row first.Text := inttostr(f); // transform int to string second.Text := inttostr(s); result.SetFocus; btn_begin.Enabled := false; // ÉèÖÿªÊ¼°´Å¥Îª²»¿ÉÓà btn_judge.Enabled := true; // Åжϰ´Å¥¿ÉÓÃend;
procedure TForm1.btn_judgeClick(Sender: TObject);begin if result.Text ='' then begin showmessage('please input a number for result..'); result.SetFocus; // Èç¹ûûÓÐÊäÈëÊý¾Ý£¬ÌáʾÊäÈë²¢»ñÈ¡½¹µã end else begin //Èç¹û»Ø´ðÕýÈ·£¬T±êÇ©¼ÓÒ»£¬·ÖÊý¼Ó5·Ö£¬·ñÔò£¬F±êÇ©¼ÓÒ»£¬²»¼Ó·Ö if strtoint(result.Text) = strtoint(first.Text)+strtoint(second.Text) then begin lab_true.Caption := inttostr((strtoint(lab_true.Caption)+1)); lab_totel.Caption := inttostr((strtoint(lab_true.Caption)*5)); btn_begin.Click; result.Clear; result.SetFocus; end else begin result.SetFocus; result.SelectAll; lab_false.Caption := inttostr((strtoint(lab_false.Caption)+1)); end; flag := flag+1; // ²âÊÔ20´Îºó£¬Ìáʾ·ÖÊýºÍËùºÄʱ£¬³ÌÐò½áÊø¡£ if flag=20 then begin showmessage('Test over,Your score is '+lab_totel.Caption+#13+ 'You spend '+ floatToStr((GetTickCount - n1) div 1000)+' second'); lab_true.Caption := '0'; lab_false.Caption := '0'; lab_totel.Caption := '0'; flag := 0; n1 := GetTickCount; btn_begin.Click; end end
end;
end.