delphi计算器的自加。。。连加连减连乘连除

发布时间:2024-05-15 05:35 发布:上海旅游网

问题描述:

我设计了一个简单的delphi计算器但是发现不能进行上面说的功能,各位大大有没办法帮忙解决一下啊?
我的代码如下
var
Form1: TForm1;
a,b,c:real;
m:string;
n:integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(Edit1.Handle,GWL_STYLE,GetWindowLong(Edit1.Handle,GWL_STYLE) or Es_right);
end;

procedure TForm1.Button1Click(Sender: TObject);//数字按钮
begin
edit1.Text:=edit1.Text+tbutton(sender).Caption ;
if n=0 then
a:=strtofloat(edit1.Text )
else
b:=strtofloat(edit1.Text );
end;

procedure TForm1.Button4Click(Sender: TObject);//+ - * /按钮
begin
m:=tbutton(sender).Caption ;
edit1.Text :='';
n:=1;
end;

procedure TForm1.Button17Click(Sender: TObject);//=按钮
begin
if m ='+' then
begin
c:=a+b;
edit1.Text :=floattostr(c);
end
else if m='-' then
begin
c:=a-b;
edit1.Text :=floattostr(c);
end
else if m='*' then
begin
c:=a*b;
edit1.Text :=floattostr(c);
end
else if m='/' then
if b=0 then
begin
showmessage('除数不能为0');
abort;
end;
c:=a/b;
edit1.text:=floattostr(c)
end;

procedure TForm1.Button18Click(Sender: TObject);//清空按钮
begin
a:=0;
b:=0;
c:=0;
m:='';
n:= 0;
edit1.Text :='';
end;

procedure TForm1.Button14Click(Sender: TObject);//+ -号
begin
if edit1.text <> '' then
edit1.Text :=floattostr(strtofloat(edit1.Text )*(-1));
end;

end.
给思路也行。

问题解答:

你的“=”只处理了单次,怎么能计算出连续的加减乘除呢?
如果想要学习编程思路
http://www.qqgb.com/Program/Delphi/DelphiSource/Program_58628.html
下载慢慢研究

热点新闻