程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 計算器(加了個小數點)

計算器(加了個小數點)

編輯:Delphi
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.
  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved