WEB开发网
开发学院软件开发Delphi 计算器(加了个小数点) 阅读

计算器(加了个小数点)

 2006-02-04 14:17:31 来源:WEB开发网   
核心提示: unit jisuanqiU;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;type TForm1 = class(TFor
 

unit jisuanqiU;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
   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;
   Panel1: TPanel;
   Edit1: TEdit;
   Button17: TButton;
   Button16: TButton;
   Button18: TButton;
   PRocedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
   procedure Button3Click(Sender: TObject);
   procedure Button4Click(Sender: TObject);
   procedure Button5Click(Sender: TObject);
   procedure Button6Click(Sender: TObject);
   procedure Button7Click(Sender: TObject);
   procedure Button8Click(Sender: TObject);
   procedure Button9Click(Sender: TObject);
   procedure Button10Click(Sender: TObject);
   procedure Button12Click(Sender: TObject);
   procedure Button13Click(Sender: TObject);
   procedure Button14Click(Sender: TObject);
   procedure Button15Click(Sender: TObject);
   procedure Button17Click(Sender: TObject);
   procedure Button16Click(Sender: TObject);
   procedure Button11Click(Sender: TObject);
   procedure FormShow(Sender: TObject);
   procedure Button18Click(Sender: TObject);
  private
   { Private declarations }
  public
   { Public declarations }
  end;

var
  Form1: TForm1;
 // num,num1,num2:integer;
  s,j,i,s_number,s_type,s_characterlast:string;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if s_type='1' then  begin
  edit1.Text:=edit1.Text+'1';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'1';
  s_type:='1';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if s_type='1' then begin
  edit1.Text:=edit1.Text+'2';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'2';
  s_type:='1';
end;
    end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if s_type='1' then begin
  edit1.Text:=edit1.Text+'3';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'3';
  s_type:='1';
end;;
    end;

procedure TForm1.Button4Click(Sender: TObject);
begin
if s_type='1' then begin
  edit1.Text:=edit1.Text+'4';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'4';
  s_type:='1';
end;
    end;

procedure TForm1.Button5Click(Sender: TObject);
begin
if s_type='1' then begin
  edit1.Text:=edit1.Text+'5';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'5';
  s_type:='1';
end;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
if s_type='1' then begin
  edit1.Text:=edit1.Text+'6';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'6';
  s_type:='1';
end;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
if s_type='1' then begin
  edit1.Text:=edit1.Text+'7';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'7';
  s_type:='1';
end;
    end;

procedure TForm1.Button8Click(Sender: TObject);
begin
if s_type='1' then  begin
  edit1.Text:=edit1.Text+'8';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'8';
  s_type:='1';
end;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
if s_type='1' then begin
  edit1.Text:=edit1.Text+'9';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'9';
  s_type:='1';
end;
end;

procedure TForm1.Button10Click(Sender: TObject);
begin

if s_type='1' then begin
  edit1.Text:=edit1.Text+'0';
  s:='123'; end
else  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'0';
  s_type:='1';
end;

end;

procedure TForm1.Button12Click(Sender: TObject);
begin
  s_type:='0';
if  s='' then
   application.MessageBox('请先输入数字','提示:',0)
else
  if  i<>'' then
  begin
     if s_characterlast='X' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) * strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='+';
       i:='';
     end;

  if s_characterlast='+' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) + strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='+';
       i:='';
    end;

   if s_characterlast='-' then
    begin
       edit1.Text:=floattostr(strtofloat(s_number) - strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='+';
       i:='';
    end;

   if s_characterlast='/' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) / strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='+';
       i:='';
     end;
  end
//**************//
   else
     begin
      s_characterlast:='+';
      s_number:=edit1.Text;
      i:='8567';
     end; 
   j:='3432';
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
  s_type:='0';
  if  s='' then

   application.MessageBox('请先输入数字','提示:',0)
else
  if  i<>'' then
  begin
     if s_characterlast='X' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) * strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='-';
       i:='';
     end;

  if s_characterlast='+' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) + strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='-';
       i:='';
    end;

   if s_characterlast='-' then
    begin
       edit1.Text:=floattostr(strtofloat(s_number) - strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='-';
       i:='';
    end;

   if s_characterlast='/' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) / strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='-';
       i:='';
     end;
  end
//**************//
   else
     begin
      s_characterlast:='-';
      s_number:=edit1.Text;
       i:='432423';
     end;
   j:='3432';
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  s_type:='0';
  if  s='' then

   application.MessageBox('请先输入数字','提示:',0)
else
  if  i<>'' then
  begin
     if s_characterlast='X' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) * strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='X';
       i:='';
     end;

  if s_characterlast='+' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) + strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='X';
       i:='';
    end;

   if s_characterlast='-' then
    begin
       edit1.Text:=floattostr(strtofloat(s_number) - strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='X';
       i:='';
    end;

   if s_characterlast='/' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) / strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='X';
       i:='';
     end;
  end
//**************//
   else
     begin
      s_characterlast:='X';
      s_number:=edit1.Text;
       i:='34342';
     end; 
   j:='3432';
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  s_type:='0';
  if  s='' then
   application.MessageBox('请先输入数字','提示:',0)
else
  if  i<>'' then
  begin
     if s_characterlast='X' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) * strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='/';
       i:='';
     end;

  if s_characterlast='+' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) + strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='/';
       i:='';
    end;

   if s_characterlast='-' then
    begin
       edit1.Text:=floattostr(strtofloat(s_number) - strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='/';
       i:='';
    end;

   if s_characterlast='/' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) / strtofloat(edit1.Text ));
       s_number:=edit1.text;
       s_characterlast:='/';
       i:='';
     end;
  end
//**************//
   else
     begin
      s_characterlast:='/';
      s_number:=edit1.Text;
       i:='3432';
     end;
   j:='3432';
end;

procedure TForm1.Button17Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
if s_type='1' then
  if (edit1.Text='')  then
  begin
  edit1.Text:=edit1.Text+'0.';
  s:='123';
  j:=''; end
  else
  begin
  edit1.Text:=edit1.Text+'.';
  s:='123'; end
else  begin
  if (j<>'') then
  begin
  edit1.text:='';
  edit1.Text:=edit1.Text+'0.';
  s_type:='1';
  j:='';
  end else
  begin
  edit1.text:='';
  edit1.text:=edit1.Text+'.';
  s_type:='1';
  end;
end;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
//=======================================//
   s_type:='0';
  if  s='' then

   application.MessageBox('请先输入数字','提示:',0)
   else
   if  s_characterlast<>'' then
  begin
     if s_characterlast='X' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) * strtofloat(edit1.Text ));
       s_number:=edit1.text;
     end;

  if s_characterlast='+' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) + strtofloat(edit1.Text ));
       s_number:=edit1.text;
    end;

   if s_characterlast='-' then
    begin
       edit1.Text:=floattostr(strtofloat(s_number) - strtofloat(edit1.Text ));
       s_number:=edit1.text;
    end;

   if s_characterlast='/' then
     begin
       edit1.Text:=floattostr(strtofloat(s_number) / strtofloat(edit1.Text ));
       s_number:=edit1.text;
     end;
   end;
   j:='3432';
end;

procedure TForm1.FormShow(Sender: TObject);
begin
j:='';
s_type:='1';
end;

procedure TForm1.Button18Click(Sender: TObject);
begin
  edit1.text:='';
end;

end.

Tags:计算器 小数点

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接