左手、莫离忧 发表于 2013-5-1 21:34:34

仿”鱼C验证系统“求助

自己仿”鱼C验证系统“,但是程序运行开始的时候,第一次总是报错,不明觉厉,求指导

左手、莫离忧 发表于 2013-5-1 21:36:25

二楼附代码

左手、莫离忧 发表于 2013-5-1 21:55:16

哎。 好冷清。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

bianbian0603 发表于 2013-5-2 11:41:58

看了你的代码,因为你启动窗口创建完毕的时候,temp3是没有赋值给他的,也就是没有计算,所以你第一次进行判断的时候就是答案空,你看看是不是这样。解决办法就是窗口创建完毕的时候,把计算结果赋给temp3。
procedure TForm1.Button2Click(Sender: TObject);
begin
if temp3 = '' then
    MessageBox(handle, '警告 您输入的答案为空', 'Brea_th贴心小提示', MB_OK)

也不知道我说的对不对,你验证一下,希望多指教,我也是新手。

bianbian0603 发表于 2013-5-2 11:52:28

因为你创建窗口完毕后,默认第一次是加法运算,所以我给你加了一句代码,测试通过
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_CENTER);
Edit1.Invalidate;
randomize;
temp1 := randomrange(0,500);
temp2 := randomrange(0,500);
temp := randomrange(0,5);
temp3:=IntToStr(temp1+temp2);
Label1.Caption := IntToStr(temp1);
Label3.Caption := IntToStr(temp2);
end;

candan 发表于 2013-5-2 12:23:22

procedure TForm1.Button2Click(Sender: TObject);
这个处理过程第一次执行 temp3 是空值,必须要先Button1Click发生后才有值
个人建议::
最好把处理过程跟比较都放在procedure TForm1.Button2Click这个过程,
Button1Click事件就让它刷新数据跟判断操作符就行了,不要计算结果

左手、莫离忧 发表于 2013-5-2 12:48:29

bianbian0603 发表于 2013-5-2 11:41 static/image/common/back.gif
看了你的代码,因为你启动窗口创建完毕的时候,temp3是没有赋值给他的,也就是没有计算,所以你第一次进行判 ...

恩恩 刚刚试了一下 确实是这样,谢谢

左手、莫离忧 发表于 2013-5-2 12:51:36

bianbian0603 发表于 2013-5-2 11:52 static/image/common/back.gif
因为你创建窗口完毕后,默认第一次是加法运算,所以我给你加了一句代码,测试通过
procedure TForm1.FormC ...

恩恩 刚刚亲测,确实如此
我是初始化的时候,就出问题了,没有对temp3赋值
谢谢

左手、莫离忧 发表于 2013-5-2 12:52:47

candan 发表于 2013-5-2 12:23 static/image/common/back.gif
procedure TForm1.Button2Click(Sender: TObject);
这个处理过程第一次执行 temp3 是空值,必须要先Button ...

procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_CENTER);
Edit1.Invalidate;
randomize;
temp1 := randomrange(0,500);
temp2 := randomrange(0,500);
temp := randomrange(0,5);
Label1.Caption := IntToStr(temp1);
Label3.Caption := IntToStr(temp2);
if temp = 1 then begin
    Label2.Caption := '+';
    temp3 := IntToStr(temp1 + temp2);
    end
else if temp = 2 then begin
    Label2.Caption := '-';
    temp3 := IntToStr(temp1 - temp2);
    end
else if temp = 3 then begin
    Label2.Caption := '*';
    temp3 := IntToStr(temp1 * temp2);
    end
else if temp = 4 then begin
    Label2.Caption := '/';
    temp3 := IntToStr(temp1 div temp2);
    end
else begin
    Label2.Caption := '%';
    temp3 := IntToStr(temp1 mod temp2);
end;
Label1.Caption := IntToStr(temp1);
Label3.Caption := IntToStr(temp2);
end;

这样就可以了,确实是初始化的问题,没注意到 汗、
页: [1]
查看完整版本: 仿”鱼C验证系统“求助