第一个delphi程序

 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.

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值