计算器的整个程序如下
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Button15: TButton;
Button16: TButton;
procedure Button4Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button4Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'1'
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'2'
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'3'
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'4'
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'5'
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'6'
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'7'
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'8'
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'9'
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
caseNof ------------------就是这里提示出错,不知怎么办?请高手!
1:temp2:=strtofloat(temp1)+strtofloat(edit1.text);
2:temp2:=strtofloat(temp1)-strtofloat(edit1.text);
3:temp2:=strtofloat(edit1.text)*strtofloat(temp1);
4:if strtofloat(edit1.text)=0 then
begin
showmessage('除数为0!');
exit;
end
else
temp2:=strtofloat(temp1)/strtofloat(edit1.text);
end;
edit1.text:=floattostr(temp2);
end;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
edit1.Clear
end;
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
n:=1;
temp1:=edit1.text;
edit1.clear;
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
n:=2;
temp1:=edit1.text;
edit1.clear;
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
n:=3;
temp1:=edit1.text;
edit1.clear;
end;
procedure TForm1.Button16Click(Sender: TObject);
begin
n:=4;
temp1:=edit1.text;
edit1.clear;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
form1.Edit1.Clear;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'0'
end;
end.