|

楼主 |
发表于 2013-5-2 12:52:47
|
显示全部楼层
candan 发表于 2013-5-2 12:23
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;
这样就可以了,确实是初始化的问题,没注意到 汗、 |
|