请大家帮我看看这段代码是什么执行的,我什么看的糊里糊涂的,谢谢大家了!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
SpeedButton16: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton12Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
s:word;
x,y:real;
v:boolean;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
s:=0;
x:=0;
y:=0;
v:=false;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if form1.Tag=1 then
begin
if tag=10 then panel2.Caption:='0.'
else panel2.Caption:=(sender as tspeedbutton).Caption;
form1.Tag:=0;
end
else panel2.Caption:=panel2.Caption+(sender as tspeedbutton).Caption;
end;
procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
form1.Tag:=1;
if v then
begin
x:=strtofloat(panel2.Caption);
v:=not v;
end
else
begin
y:=strtofloat(panel2.Caption);
case s of
0:panel2.Caption:=format('%g',[x+y]);
1:panel2.Caption:=format('%g',[x-y]);
2:panel2.Caption:=format('%g',[x*y]);
3:if y<>0 then
panel2.Caption:=format('%g',[x/y])
else
begin
showmessage('不能以0为除数!');
panel2.Caption:=format('%g',[x]);
v:=false;
end;
4:begin
y:=0;
v:=false;
end;
end;
x:=strtofloat(panel2.Caption);
end;
s:=(sender as tspeedbutton).Tag;
end;
end.