Arsip: Cool Calculator


by JoeSand in Serba Neka more 12 years ago 2548
Dah Bosan dengan kalkulator bawaan windows?... Klo ya Yuk kita buat sendiri....Berikut adalah Sourcenya.

unit UCal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, XPMan, StdCtrls, ComCtrls, ActnList, AppEvnts, Mask, ExtCtrls,clipbrd;
type
TForm2 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button0: TButton;
Edit1: TEdit;
Button00: TButton;
Button000: TButton;
ButtonTambah: TButton;
ButtonKurang: TButton;
ButtonKali: TButton;
ButtonBagi: TButton;
ButtonDot: TButton;
ButtonClear: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Panel1: TPanel;
Panel2: TPanel;
UpDown: TButton;
Label1: TLabel;
ButtonDel: TButton;
Button15: TButton;
procedure Button15Click(Sender: TObject);
procedure ButtonDelClick(Sender: TObject);
procedure FormClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure UpDownClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure ApplicationEvents1ActionExecute(Action: TBasicAction;
var Handled: Boolean);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure Button9KeyPress(Sender: TObject; var Key: Char);
procedure Button8KeyPress(Sender: TObject; var Key: Char);
procedure Button7KeyPress(Sender: TObject; var Key: Char);
procedure Button6KeyPress(Sender: TObject; var Key: Char);
procedure Button5KeyPress(Sender: TObject; var Key: Char);
procedure Button4KeyPress(Sender: TObject; var Key: Char);
procedure Button3KeyPress(Sender: TObject; var Key: Char);
procedure Button2KeyPress(Sender: TObject; var Key: Char);
procedure HotKey1Change(Sender: TObject);
procedure HotKey1Enter(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure ButtonClearClick(Sender: TObject);
procedure ButtonDotClick(Sender: TObject);
procedure ButtonBagiClick(Sender: TObject);
procedure ButtonKaliClick(Sender: TObject);
procedure ButtonKurangClick(Sender: TObject);
procedure ButtonTambahClick(Sender: TObject);
procedure Button000Click(Sender: TObject);
procedure Button00Click(Sender: TObject);
procedure Button0Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure DoOperasi(Operasi:Byte );
{ Private declarations }
public
function Add(inp,inp2: real):real;
function Sub(inp,inp2: real): real;
function mul(inp,inp2:real): real;
function divide(inp,inp2: real):real;
function Power2(inp: real):real;
function Power3(inp: real):real;
var
temp:string;
Temp2:string;
operasi: byte;
Operand1: Double;
Operand2: Double;
Ans: string;
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R .dfm}
function TForm2.Add(inp,inp2: real): real;
begin
result:= Inp+ Inp2;
end;
function TForm2.Sub(inp,inp2: real): real;
begin
result:= Inp - Inp2;
end;
function TForm2.mul(inp,inp2: real): real;
begin
result:= Inp   Inp2;
end;
function TForm2.divide(inp,inp2: real): real;
begin
try
result:= Inp/Inp2;
except
Edit1.Text:= 'ERROR DAB!!!';
showMessage('Error Pembagian dg Nol');
Operand1:=0;
Result:= 0;
end;
end;
function TForm2.Power2(inp: real):real;
begin
result:= Inpinp;
end;
function TForm2.Power3(inp: real):real;
begin
result:= Inp inp*inp;
end;
procedure TForm2.DoOperasi(Operasi:Byte );
var op: String;
begin
if temp<>'' then  Operand2:= strtoFloat(temp);
case Operasi of
1:
begin
Edit1.Text := floatToStr(Add(Operand1, Operand2));
Operasi := 0;
Op:='Tambah[+]';
end;
2:
begin
Edit1.Text := floatToStr(Sub(Operand1, Operand2));
Operasi := 0;
Op:='Kurang[-]';
end;
3:
begin
Edit1.Text := floatToStr(mul(Operand1, Operand2));
Operasi := 0;
Op:='Kali[X]';
end;
4:
begin
Edit1.Text := floatToStr(Divide(Operand1, Operand2));
Operasi := 0;
Op:='Bagi[/]';
end;
end;
Label1.caption:= 'Operand1:= '+ floattostr(Operand1)+ ', Operand2:= '+ floattostr(Operand2)+
', Operasi:= '+ OP;
Operand1:=strtoFloat(Edit1.Text);
end;
procedure TForm2.FormActivate(Sender: TObject);
begin
form2.ClientHeight:=250;
end;
procedure TForm2.FormClick(Sender: TObject);
begin
form2.ClientHeight:=250;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
Edit1.BiDiMode:= bdRightToLeft;
Panel1.Color:=clred;
end;
procedure TForm2.FormKeyPress(Sender: TObject; var Key: Char);
begin
//  if key='9' then
//  Button9.Click;
end;
procedure TForm2.HotKey1Change(Sender: TObject);
begin
Button1.Click;
end;
procedure TForm2.HotKey1Enter(Sender: TObject);
begin
Button1.Click;
end;
procedure TForm2.Button0Click(Sender: TObject);
begin
temp:= Temp+ '0';
Edit1.Text:= temp;
end;
procedure TForm2.Button00Click(Sender: TObject);
begin
temp:= Temp+ '00';
Edit1.Text:= temp;
end;
procedure TForm2.ApplicationEvents1ActionExecute(Action: TBasicAction;
var Handled: Boolean);
begin
//  label2.caption:=inttostr(Action.Tag);
end;
procedure TForm2.Button000Click(Sender: TObject);
begin
temp:= Temp+ '000';
Edit1.Text:= temp;
end;
procedure TForm2.Button10Click(Sender: TObject);
begin
if Operasi<>0 then
DoOperasi(Operasi);
Ans:= Edit1.Text;
temp:='';
Operasi:=0;
Edit1.SelectAll;
Edit1.CopyToClipboard;
end;
procedure TForm2.Button11Click(Sender: TObject);
begin
temp:= Temp+ '000000';
Edit1.Text:= temp;
end;
procedure TForm2.Button12Click(Sender: TObject);
begin
temp:=Ans;
Edit1.Text:= temp;
end;
procedure TForm2.Button13Click(Sender: TObject);
begin
temp:= Edit1.Text;
if temp<>'' then  Operand1:= strtoFloat(temp);
Edit1.Text:=floattoStr(power2(Operand1));
Operand1:= strtoFloat(Edit1.Text)
end;
procedure TForm2.Button14Click(Sender: TObject);
begin
temp:= Edit1.Text;
if temp<>'' then  Operand1:= strtoFloat(temp);
Edit1.Text:=floattoStr(power3(Operand1));
Operand1:= strtoFloat(Edit1.Text)
end;
procedure TForm2.Button15Click(Sender: TObject);
var SpVoice, voice: Variant;
begin
end;
procedure TForm2.ButtonDelClick(Sender: TObject);
begin
Edit1.Text:=   Copy (Edit1.Text,1,Length( Edit1.Text)-1);
temp:= Edit1.Text;
if length(Edit1.Text)=0 then Edit1.Text:= '0';
end;
procedure TForm2.UpDownClick(Sender: TObject);
begin
if UpDown.Caption='>>' then
begin
form2.ClientHeight:=271;
UpDown.Caption:='<<' ;
end
else
begin
form2.Height:=40;
UpDown.Caption:='>>';
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
temp:=Temp+ '1';
Edit1.Text:= temp;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
temp:= Temp+ '2';
Edit1.Text:= temp;
end;
procedure TForm2.Button2KeyPress(Sender: TObject; var Key: Char);
begin
//  if key='2' then
//  Label2.Caption:= key;
//   Button2.Click;
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
temp:= Temp+ '3';
Edit1.Text:= temp;
end;
procedure TForm2.Button3KeyPress(Sender: TObject; var Key: Char);
begin
Button3.Click;
end;
procedure TForm2.Button4Click(Sender: TObject);
begin
temp:= Temp+ '4';
Edit1.Text:= temp;
end;
procedure TForm2.Button4KeyPress(Sender: TObject; var Key: Char);
begin
Button4.Click;
end;
procedure TForm2.Button5Click(Sender: TObject);
begin
temp:= Temp+ '5';
Edit1.Text:= temp;
end;
procedure TForm2.Button5KeyPress(Sender: TObject; var Key: Char);
begin
Button5.Click;
end;
procedure TForm2.Button6Click(Sender: TObject);
begin
temp:= Temp+ '6';
Edit1.Text:= temp;
end;
procedure TForm2.Button6KeyPress(Sender: TObject; var Key: Char);
begin
Button6.Click;
end;
procedure TForm2.Button7Click(Sender: TObject);
begin
temp:= Temp+ '7';
Edit1.Text:= temp;
end;
procedure TForm2.Button7KeyPress(Sender: TObject; var Key: Char);
begin
Button7.Click;
end;
procedure TForm2.Button8Click(Sender: TObject);
begin
temp:= Temp+ '8';
Edit1.Text:= temp;
end;
procedure TForm2.Button8KeyPress(Sender: TObject; var Key: Char);
begin
Button8.Click;
end;
procedure TForm2.Button9Click(Sender: TObject);
begin
temp:= Temp+ '9';
Edit1.Text:= temp;
end;
procedure TForm2.Button9KeyPress(Sender: TObject; var Key: Char);
begin
// if key=#9 then
//  Button9.Click;
////  Label2.Caption:= key;
end;
procedure TForm2.ButtonClearClick(Sender: TObject);
begin
temp:= '';
Operand1:=0;
Operand2:=0;
Operasi:=0;
Edit1.Text:= temp;
Label1.Caption:='';
end;
procedure TForm2.ButtonDotClick(Sender: TObject);
begin
temp:= Temp+ '.';
Edit1.Text:= temp;
end;
procedure TForm2.ButtonKaliClick(Sender: TObject);
begin
if operasi<>0 then
begin
doOperasi(OPerasi);
temp:='';
Operasi:= 3;
end
else
begin
if temp<>'' then  Operand1:= strtoFloat(temp);
temp:='';
Edit1.Text:= temp;
Operasi:= 3;
end;
end;
procedure TForm2.ButtonBagiClick(Sender: TObject);
begin
if operasi<>0 then
begin
doOperasi(OPerasi);
temp:='';
Operasi:= 4;
end
else
begin
if temp<>'' then  Operand1:= strtoFloat(temp);
temp:='';
Edit1.Text:= temp;
Operasi:= 4;
end;
end;
procedure TForm2.ButtonKurangClick(Sender: TObject);
begin
if operasi<>0 then
begin
doOperasi(OPerasi);
temp:='';
Operasi:= 2;
end
else
begin
if temp<>'' then  Operand1:= strtoFloat(temp);
temp:='';
Edit1.Text:= temp;
Operasi:= 2;
end;
end;
procedure TForm2.ButtonTambahClick(Sender: TObject);
begin
if operasi<>0 then
begin
doOperasi(OPerasi);
temp:='';
Operasi:= 1;
end
else
begin
if temp<>'' then  Operand1:= strtoFloat(temp);
temp:='';
Edit1.Text:= temp;
Operasi:= 1;
end;
end;
end.
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com