首页 > 代码库 > 计算器(delphi)
计算器(delphi)
1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, StdCtrls, bsSkinData, BusinessSkinForm, Mask, bsSkinBoxCtrls, bscalc, 8 bsSkinCtrls; 9 10 type 11 TForm1 = class(TForm) 12 Button2: TButton; 13 Button3: TButton; 14 Button4: TButton; 15 Button5: TButton; 16 Button6: TButton; 17 Button7: TButton; 18 Button8: TButton; 19 Button9: TButton; 20 Button10: TButton; 21 Button11: TButton; 22 Button12: TButton; 23 Button13: TButton; 24 Button14: TButton; 25 Button15: TButton; 26 Button16: TButton; 27 Button17: TButton; 28 Button18: TButton; 29 Button19: TButton; 30 Button20: TButton; 31 Button21: TButton; 32 Button22: TButton; 33 bsBusinessSkinForm1: TbsBusinessSkinForm; 34 bsSkinData1: TbsSkinData; 35 Edit1: TbsSkinEdit; 36 bsCompressedStoredSkin1: TbsCompressedStoredSkin; 37 Edit2: TbsSkinEdit; 38 Edit3: TbsSkinEdit; 39 Edit4: TbsSkinEdit; 40 Label1: TLabel; 41 Button1: TButton; 42 Button23: TButton; 43 procedure Button1Click(Sender: TObject); 44 procedure FormCreate(Sender: TObject); 45 procedure Button2Click(Sender: TObject); 46 procedure Button3Click(Sender: TObject); 47 procedure Button4Click(Sender: TObject); 48 procedure Button5Click(Sender: TObject); 49 procedure Button6Click(Sender: TObject); 50 procedure Button7Click(Sender: TObject); 51 procedure Button8Click(Sender: TObject); 52 procedure Button9Click(Sender: TObject); 53 procedure Button10Click(Sender: TObject); 54 procedure Button11Click(Sender: TObject); 55 procedure Button12Click(Sender: TObject); 56 procedure Button13Click(Sender: TObject); 57 procedure Button14Click(Sender: TObject); 58 procedure Button15Click(Sender: TObject); 59 procedure Button16Click(Sender: TObject); 60 procedure Edit1Change(Sender: TObject); 61 procedure Edit3Change(Sender: TObject); 62 procedure Edit1Enter(Sender: TObject); 63 procedure Edit3Enter(Sender: TObject); 64 procedure Button17Click(Sender: TObject); 65 procedure Button18Click(Sender: TObject); 66 procedure Button19Click(Sender: TObject); 67 procedure Button20Click(Sender: TObject); 68 procedure Button21Click(Sender: TObject); 69 procedure Button22Click(Sender: TObject); 70 procedure bsSkinButton1Click(Sender: TObject); 71 procedure Button23Click(Sender: TObject); 72 private 73 { Private declarations } 74 public 75 { Public declarations } 76 77 end; 78 79 var 80 Form1: TForm1; 81 str1:String; 82 str2:String; 83 int1:real; 84 int2:real; 85 bo:real; 86 result:real; 87 implementation 88 89 {$R *.dfm} 90 91 procedure TForm1.Button1Click(Sender: TObject); 92 begin 93 94 if bo=0 then 95 begin 96 str1:=str1+‘1‘; 97 Edit1.Text:=str1; 98 end 99 Else100 begin101 str2:=str2+‘1‘;102 Edit3.Text:=str2;103 end104 105 106 end;107 108 procedure TForm1.FormCreate(Sender: TObject);109 begin110 111 int1:=0;112 int2:=0;113 bo:=0;114 SetWindowLong(Edit1.Handle,GWL_STYLE,GetWindowLong(Edit1.Handle,GWL_STYLE) or Es_right);115 SetWindowLong(Edit2.Handle,GWL_STYLE,GetWindowLong(Edit2.Handle,GWL_STYLE) or Es_right);116 SetWindowLong(Edit3.Handle,GWL_STYLE,GetWindowLong(Edit3.Handle,GWL_STYLE) or Es_right);117 SetWindowLong(Edit4.Handle,GWL_STYLE,GetWindowLong(Edit4.Handle,GWL_STYLE) or Es_right);118 end;119 120 procedure TForm1.Button20Click(Sender: TObject);121 begin122 edit2.Text:=‘‘;123 edit3.Text:=‘‘;124 int2:=0;125 edit4.Text:= FormatFloat(‘0.00000‘,1/int1) ;126 end;127 128 procedure TForm1.Button21Click(Sender: TObject);129 begin130 edit2.Text:=‘‘;131 edit3.Text:=‘‘;132 int2:=0;133 edit4.Text:= FormatFloat(‘0.00000‘,Sqrt(int1)) ;134 end;135 136 procedure TForm1.Button22Click(Sender: TObject);137 begin138 result:=int1*int2/100;139 Edit4.Text:=FormatFloat(‘0.00000‘,result);140 end;141 142 procedure TForm1.Button23Click(Sender: TObject);143 begin144 if bo=0 then145 edit1.Text:=‘‘146 else147 edit3.Text:=‘‘;148 149 end;150 151 procedure TForm1.Button2Click(Sender: TObject);152 153 154 begin155 if bo=0 then156 begin157 str1:=str1+‘2‘;158 Edit1.Text:=str1;159 end160 Else161 begin162 str2:=str2+‘2‘;163 Edit3.Text:=str2;164 end165 end;166 167 procedure TForm1.Button3Click(Sender: TObject);168 begin169 if bo=0 then170 begin171 str1:=str1+‘3‘;172 Edit1.Text:=str1;173 end174 Else175 begin176 str2:=str2+‘3‘;177 Edit3.Text:=str2;178 end179 end;180 181 procedure TForm1.Button4Click(Sender: TObject);182 begin183 if bo=0 then184 begin185 str1:=str1+‘4‘;186 Edit1.Text:=str1;187 end188 Else189 begin190 str2:=str2+‘4‘;191 Edit3.Text:=str2;192 end193 end;194 195 procedure TForm1.Button5Click(Sender: TObject);196 begin197 if bo=0 then198 begin199 str1:=str1+‘5‘;200 Edit1.Text:=str1;201 end202 Else203 begin204 str2:=str2+‘5‘;205 Edit3.Text:=str2;206 end207 end;208 209 procedure TForm1.Button6Click(Sender: TObject);210 begin211 if bo=0 then212 begin213 str1:=str1+‘6‘;214 Edit1.Text:=str1;215 end216 Else217 begin218 str2:=str2+‘6‘;219 Edit3.Text:=str2;220 end221 end;222 223 procedure TForm1.Button7Click(Sender: TObject);224 begin225 if bo=0 then226 begin227 str1:=str1+‘7‘;228 Edit1.Text:=str1;229 end230 Else231 begin232 str2:=str2+‘7‘;233 Edit3.Text:=str2;234 end235 end;236 237 procedure TForm1.Button8Click(Sender: TObject);238 begin239 if bo=0 then240 begin241 str1:=str1+‘8‘;242 Edit1.Text:=str1;243 end244 Else245 begin246 str2:=str2+‘8‘;247 Edit3.Text:=str2;248 end249 end;250 251 procedure TForm1.Button9Click(Sender: TObject);252 begin253 if bo=0 then254 begin255 str1:=str1+‘9‘;256 Edit1.Text:=str1;257 end258 Else259 begin260 str2:=str2+‘9‘;261 Edit3.Text:=str2;262 end263 end;264 265 procedure TForm1.Edit1Change(Sender: TObject);266 begin267 str1:=edit1.Text;268 if edit1.Text<>‘‘ then269 int1:=strtofloat(edit1.Text)270 else271 int1:=0;272 273 end;274 275 procedure TForm1.Edit1Enter(Sender: TObject);276 begin277 bo:=0;278 end;279 280 procedure TForm1.Edit3Change(Sender: TObject);281 begin282 str2:=edit3.Text;283 if edit3.Text<>‘‘ then284 int2:=strtofloat(edit3.Text)285 else286 int2:=0;287 288 end;289 290 procedure TForm1.Edit3Enter(Sender: TObject);291 begin292 bo:=1;293 end;294 295 procedure TForm1.bsSkinButton1Click(Sender: TObject);296 begin297 if bo=0 then298 begin299 str1:=str1+‘1‘;300 Edit1.Text:=str1;301 end302 Else303 begin304 str2:=str2+‘1‘;305 Edit3.Text:=str2;306 end307 end;308 309 procedure TForm1.Button10Click(Sender: TObject);310 begin311 if bo=0 then312 begin313 str1:=str1+‘0‘;314 Edit1.Text:=str1;315 end316 Else317 begin318 str2:=str2+‘0‘;319 Edit3.Text:=str2;320 end321 end;322 323 procedure TForm1.Button11Click(Sender: TObject);324 begin325 bo:=1;326 Edit2.Text:=‘+‘;327 end;328 329 procedure TForm1.Button12Click(Sender: TObject);330 begin331 bo:=1;332 Edit2.Text:=‘-‘;333 end;334 335 procedure TForm1.Button13Click(Sender: TObject);336 begin337 bo:=1;338 Edit2.Text:=‘*‘;339 end;340 341 procedure TForm1.Button14Click(Sender: TObject);342 begin343 bo:=1;344 Edit2.Text:=‘/‘;345 end;346 347 procedure TForm1.Button15Click(Sender: TObject);348 begin349 350 351 if Edit2.Text=‘+‘ then352 begin353 result:=int1+int2;354 Edit4.Text:=floattostr(result);355 end ;356 357 358 if Edit2.Text=‘-‘ then359 begin360 result:=int1-int2;361 Edit4.Text:=floattostr(result);362 end ;363 if Edit2.Text=‘*‘ then364 begin365 result:=int1*int2;366 Edit4.Text:=floattostr(result);367 end ;368 if ( Edit2.Text=‘/‘) and (int2<>0 ) then369 begin370 result:=int1/int2;371 {保留5位小数}372 Edit4.Text:=FormatFloat(‘0.00000‘,result);373 end ;374 375 if ( Edit2.Text=‘/‘) and (int2=0 ) then376 begin377 Application.MessageBox(‘除数不能为0!‘,‘错误提示‘,MB_OKCANCEL);378 end ;379 380 381 end;382 383 384 procedure TForm1.Button16Click(Sender: TObject);385 begin386 387 388 bo:=0;389 Edit1.Text:=‘‘;390 Edit2.Text:=‘‘;391 Edit3.Text:=‘‘;392 Edit4.Text:=‘‘;393 int1:=0;394 int2:=0;395 result:=0;396 end;397 398 procedure TForm1.Button17Click(Sender: TObject);399 begin400 if bo=0 then401 edit1.Text:= Copy( edit1.Text, 1, length( Edit1.text )-1 ) {截取}402 else403 edit3.Text:= Copy( edit3.Text, 1, length( Edit3.text )-1 );404 405 406 end;407 408 procedure TForm1.Button18Click(Sender: TObject);409 begin410 if bo=0 then411 begin412 str1:=str1+‘.‘;413 Edit1.Text:=str1;414 end415 Else416 begin417 str2:=str2+‘.‘;418 Edit3.Text:=str2;419 end420 end;421 422 procedure TForm1.Button19Click(Sender: TObject);423 begin424 if bo=0 then425 begin426 if int1>0 then427 edit1.Text:=‘-‘+edit1.Text428 else429 begin430 int1:=0-strtofloat(edit1.Text);431 edit1.Text:=floattostr(int1) ;432 end;433 434 end435 436 else437 begin438 if int2>0 then439 edit3.Text:=‘-‘+edit3.Text440 else441 begin442 int2:=0-strtofloat(edit3.Text);443 edit3.Text:=floattostr(int2) ;444 end;445 end;446 end;447 448 end.
计算器(delphi)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。