⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 标准型和科学型。 标准型带有足够让你用手指来操作的按钮
💻 PAS
字号:
unit Unit1;

interface

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

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;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    Button20: TButton;
    Button21: TButton;
    Button22: TButton;
    Button23: TButton;
    Edit1: TEdit;
    procedure Button10Click(Sender: TObject);
    procedure Button18Click(Sender: TObject);
    procedure Button21Click(Sender: TObject);
    procedure Button22Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button23Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button17Click(Sender: TObject);
    procedure Button16Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Button20Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button15Click(Sender: TObject);
    procedure Button19Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure caozys(a,b:double;op:char);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  num1,num2:string;//两个操作数;
  coperation:char;//操作运算符;
  cop:boolean;//判断操作运算符是否按下;

implementation

{$R *.dfm}
procedure TForm1.caozys(a,b:double;op:char);  //运算模型;
var
  result:double;
begin
  case op of
  '+':result:=a+b;
  '-':result:=a-b;
  '*':result:=a*b;
  '/':result:=a/b;
  '%':result:=trunc(a) mod trunc(b);
  's':result:=sqrt(a);
  'x':result:=1/a;
  '^':result:= power(a,b);
  end;
  num1:=floattostr(result);
  num2:='';
  coperation:=' ';
  edit1.text:=num1;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'1';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'1';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'2';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'2';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'3';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'3';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button19Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'4';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'4';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button15Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'5';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'5';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button14Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'6';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'6';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button20Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'7';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'7';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button13Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'8';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'8';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'9';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'9';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button16Click(Sender: TObject);
begin
  if(cop=false) then
  begin
  num1:=num1+'0';
  edit1.Text:=num1;
  end;
  if(cop=true) and (num1<>'') then
  begin
  num2:=num2+'0';
  edit1.Text:=num2;
  end;
end;

procedure TForm1.Button17Click(Sender: TObject);
begin
   cop:=true;
   if (num1<>'') and (num2<>'') then
      begin
         caozys(strtofloat(num1),strtofloat(num2),coperation);
      end;
   coperation:='+';
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
   cop:=true;
   if (num1<>'') and (num2<>'') then
      begin
         caozys(strtofloat(num1),strtofloat(num2),coperation);
      end;
   coperation:='-';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
   cop:=true;
   if (num1<>'') and (num2<>'') then
      begin
         caozys(strtofloat(num1),strtofloat(num2),coperation);
      end;
   coperation:='*';
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
   cop:=true;
   if (num1<>'') and (num2<>'') then
      begin
         caozys(strtofloat(num1),strtofloat(num2),coperation);
      end;
   coperation:='/';
end;

procedure TForm1.Button23Click(Sender: TObject);
begin
   cop:=true;
   if (num1<>'') and (num2<>'') then
      begin
         caozys(strtofloat(num1),strtofloat(num2),coperation);
      end;
   coperation:='^';
end;

procedure TForm1.Button12Click(Sender: TObject);
begin
   cop:=true;
   if (num1<>'') and (num2<>'') then
      begin
         caozys(strtofloat(num1),strtofloat(num2),coperation);
      end;
   coperation:='%';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  cop:=true;
  coperation:='s';
   if (num1<>'') then
      begin
         caozys(strtofloat(num1),0,coperation);
      end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  cop:=true;
  coperation:='x';
   if (num1<>'') then
      begin
         caozys(strtofloat(num1),0,coperation);
      end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if (num1<>'') and (num2<>'') and (coperation<>' ') then
      begin
         caozys(strtofloat(num1),strtofloat(num2),coperation);
      end;
end;

procedure TForm1.Button22Click(Sender: TObject);
begin
  edit1.clear;
  num1:='';
  num2:='';
  coperation:=' ';
  cop:=false;
end;

procedure TForm1.Button21Click(Sender: TObject);
var
  copyresult:string;
begin
  copyresult:=copy(edit1.Text,1,length(edit1.Text)-1);
  if cop=false then
     num1:=copy(num1,1,length(num1)-1);
  if (cop=true)and(num1<>'') then
     num2:=copy(num2,1,length(num2)-1);
  edit1.Text:=copyresult;
end;

procedure TForm1.Button18Click(Sender: TObject);
begin
  if cop=false then
     begin
       if pos('-',num1)=0 then
          num1:='-'+num1;
       edit1.Text:=num1;
     end;
  if (cop=true)and(num1<>'') then
     begin
       if pos('-',num2)=0 then
          num2:='-'+num2;
       edit1.Text:=num2;
     end;
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
  if cop=false then
     begin
       if pos('.',num1)=0 then
          num1:=num1+'.';
       edit1.Text:=num1;
     end;
  if (cop=true)and(num1<>'') then
     begin
       if pos('.',num2)=0 then
          num2:=num2+'.';
       edit1.Text:=num2;
     end;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  //showmessage(inttostr(key));
  if (key=55) or (key=103) then
      Button20.Click;
  if (key=107) or (key=187) then
      Button17.Click;
  if (key=48) or (key=96) then
      Button16.Click;
  if (key=110) or (key=190) then
      Button10.Click;
  if (key=49) or (key=97) then
      Button11.Click;
  if (key=50) or (key=98) then
      Button9.Click;
  if (key=51) or (key=99) then
      Button8.Click ;
  if (key=52) or (key=100) then
      Button19.Click;
  if (key=53) or (key=101) then
      Button15.Click;
  if (key=54) or (key=102) then
      Button14.Click;
  if (key=56) or (key=104) then
      Button13.Click;
  if (key=57) or (key=105) then
      Button7.Click;
  if (key=109) or (key=189) then
      Button6.Click;
  if (key=56) or (key=106) then
      Button4.Click;
  if (key=111) or (key=191) then
      Button5.Click;
  if (key=8)  then
      Button21.Click;
end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -