zoukankan      html  css  js  c++  java
  • 计算器(思想)

    unit Unit1;

    interface

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

    type
      TForm1 = class(TForm)
        edt1: TEdit;
        btn1: TButton;
        btn2: TButton;
        btn3: TButton;
        btn4: TButton;
        btn5: TButton;
        btn6: TButton;
        btn7: TButton;
        btn8: TButton;
        btn9: TButton;
        btn10: TButton;
        btn11: TButton;
        btn12: TButton;
        btn13: TButton;
        btn14: TButton;
        btn15: TButton;
        btn16: TButton;
        btn17: TButton;
        procedure FormCreate(Sender: TObject);
        procedure btn17Click(Sender: TObject);
        procedure btn1Click(Sender: TObject);
        procedure btn2Click(Sender: TObject);
        procedure btn3Click(Sender: TObject);
        procedure btn6Click(Sender: TObject);
        procedure btn7Click(Sender: TObject);
        procedure btn8Click(Sender: TObject);
        procedure btn10Click(Sender: TObject);
        procedure btn11Click(Sender: TObject);
        procedure btn12Click(Sender: TObject);
        procedure btn15Click(Sender: TObject);
        procedure btn14Click(Sender: TObject);
        procedure btn4Click(Sender: TObject);
        procedure btn5Click(Sender: TObject);
        procedure btn9Click(Sender: TObject);
        procedure btn13Click(Sender: TObject);
        procedure btn16Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        op:Char;
        fg:Boolean;
        nm:Double;
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      op:='a';
      fg:=False;
      nm:=0;
    end;

    procedure TForm1.btn17Click(Sender: TObject);
    begin
      edt1.Text:='';
      op:='a';
      fg:=False;
      nm:=0;
    end;

    procedure TForm1.btn1Click(Sender: TObject);
    begin
      if fg=True then
      begin
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='1';
      end else
      edt1.Text:=edt1.Text+'1';
    end;

    procedure TForm1.btn2Click(Sender: TObject);
    begin
      if fg=True then
      begin   
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='2';
      end else
      edt1.Text:=edt1.Text+'2';
    end;

    procedure TForm1.btn3Click(Sender: TObject);
    begin
      if fg=True then
      begin    
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='3';
      end else
      edt1.Text:=edt1.Text+'3';
    end;

    procedure TForm1.btn6Click(Sender: TObject);
    begin
      if fg=True then
      begin   
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='4';
      end else
      edt1.Text:=edt1.Text+'4';
    end;

    procedure TForm1.btn7Click(Sender: TObject);
    begin
      if fg=True then
      begin  
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='5';
      end else
      edt1.Text:=edt1.Text+'5';
    end;

    procedure TForm1.btn8Click(Sender: TObject);
    begin
      if fg=True then
      begin  
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='6';
      end else
      edt1.Text:=edt1.Text+'6';
    end;

    procedure TForm1.btn10Click(Sender: TObject);
    begin
      if fg=True then
      begin 
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='7';
      end else
      edt1.Text:=edt1.Text+'7';
    end;

    procedure TForm1.btn11Click(Sender: TObject);
    begin
      if fg=True then
      begin  
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='8';
      end else
      edt1.Text:=edt1.Text+'8';
    end;

    procedure TForm1.btn12Click(Sender: TObject);
    begin
      if fg=True then
      begin  
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='9';
      end else
      edt1.Text:=edt1.Text+'9';
    end;

    procedure TForm1.btn15Click(Sender: TObject);
    begin
      if fg=True then
      begin   
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='0';
      end else
      edt1.Text:=edt1.Text+'0';
    end;

    procedure TForm1.btn14Click(Sender: TObject);
    begin
      if fg=True then
      begin    
        nm:=StrToCurr(edt1.Text);
        edt1.Text:='';
        fg:=False;
        edt1.Text:='0.';
      end else
      edt1.Text:=edt1.Text+'.';
    end;

    procedure TForm1.btn4Click(Sender: TObject);
    begin
      case op of
      '+':
        edt1.Text:=CurrToStr(nm+strtocurr(edt1.Text));
      '-':
        edt1.Text:=CurrToStr(nm-strtocurr(edt1.Text));
      '*':
        edt1.Text:=CurrToStr(nm*strtocurr(edt1.Text));
      '/':
        edt1.Text:=CurrToStr(nm/strtocurr(edt1.Text));
    //  else
    //    edt1.Text:=edt1.Text;
      end;
      fg:=True;
      op:='+';
    end;

    procedure TForm1.btn5Click(Sender: TObject);
    begin
      case op of
      '+':
        edt1.Text:=CurrToStr(nm+strtocurr(edt1.Text));
      '-':
        edt1.Text:=CurrToStr(nm-strtocurr(edt1.Text));
      '*':
        edt1.Text:=CurrToStr(nm*strtocurr(edt1.Text));
      '/':
        edt1.Text:=CurrToStr(nm/strtocurr(edt1.Text));
    //  else
    //    edt1.Text:=edt1.Text;
      end;
      fg:=True;
      op:='-';
    end;

    procedure TForm1.btn9Click(Sender: TObject);
    begin
      case op of
      '+':
        edt1.Text:=CurrToStr(nm+strtocurr(edt1.Text));
      '-':
        edt1.Text:=CurrToStr(nm-strtocurr(edt1.Text));
      '*':
        edt1.Text:=CurrToStr(nm*strtocurr(edt1.Text));
      '/':
        edt1.Text:=CurrToStr(nm/strtocurr(edt1.Text));
    //  else
    //    edt1.Text:=edt1.Text;
      end;
      fg:=True;
      op:='*';
    end;

    procedure TForm1.btn13Click(Sender: TObject);
    begin
      case op of
      '+':
        edt1.Text:=CurrToStr(nm+strtocurr(edt1.Text));
      '-':
        edt1.Text:=CurrToStr(nm-strtocurr(edt1.Text));
      '*':
        edt1.Text:=CurrToStr(nm*strtocurr(edt1.Text));
      '/':
        edt1.Text:=CurrToStr(nm/strtocurr(edt1.Text));
    //  else
    //    edt1.Text:=edt1.Text;
      end;
      fg:=True;
      op:='/';
    end;

    procedure TForm1.btn16Click(Sender: TObject);
    begin
      case op of
      '+':
        edt1.Text:=CurrToStr(nm+StrToCurr(edt1.Text));
      '-':
        edt1.Text:=CurrToStr(nm-StrToCurr(edt1.Text));
      '*':
        edt1.Text:=CurrToStr(nm*StrToCurr(edt1.Text));
      '/':
        edt1.Text:=CurrToStr(nm/StrToCurr(edt1.Text));
    //  else
    //    edt1.Text:=edt1.Text;
      end;
      nm:=0;
      fg:=True;
    end;

    end.

  • 相关阅读:
    Modbus Tcp[转载]
    NModbus使用示例
    “SAP.Middleware.Connector.RfcConfigParameters”的类型初始值设定项引发异常,解决方法
    .net x64 x86 any cpu
    虚拟机vmware 15的安装和使用
    nuget下载包,搜索到的包很少
    做一款简单、高效、好用的文件同步工具
    [WeUiSharp] 基于WPF实现的仿Windows桌面版微信UI界面库
    C语言----结构与联合(基础篇十一)
    C语言----字符串(基础篇十)
  • 原文地址:https://www.cnblogs.com/760044827qq/p/3099179.html
Copyright © 2011-2022 走看看