Pada program ini kami hanya menggunakan beberapa komponen sesuai dengan sobat lihat di gambar, ada beberapa button, dan 1 memo, disini kami tidak mengubah properties di setiap komponen yang kami gunakan. Langsung saja sobat lihat listingnya
Source code (Listing)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
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;
Label2: TLabel;
memo1: TMemo;
Button19: TButton;
Button18: TButton;
Button20: TButton;
procedure FormCreate(Sender: TObject);
procedure Button18Click(Sender: TObject);
procedure Button19Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
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 Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure Button20Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MemAngka,MemLogic,MemOperator,MemSimpan:string;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Clear
end;
procedure TForm1.Button18Click(Sender: TObject);
begin
{setting ketika tombol on ditekan}
Memo1.Text:='0';
{membuat layar kalkulator berisi angka 0}
MemLogic:='0';
{merubah nilai variable MemLogic menjadi 0}
MemOperator :='';
{mengosongkan nilai variable MemOperator}
MemAngka :='0';
{merubah nilai variable MemAngka menjadi 0}
end;
procedure TForm1.Button19Click(Sender: TObject);
begin
memo1.clear; {mengosongkan tampilan layar calculator}
MemLogic:='';
MemSimpan :='0';
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
if MemOperator<>'' then memo1.Text:='0' else
if memo1.text='0' then memo1.text:='0' else
begin
memo1.Text:=memo1.Text+'0';
MemLogic:='1';
end;
end
else
memo1.Text:=memo1.Text+'0';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='1' else
memo1.text:='1';
end
else
memo1.Text:=memo1.Text+'1';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='2' else
memo1.text:='2';
end
else
memo1.Text:=memo1.Text+'2';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='3' else
memo1.text:='3';
end
else
memo1.Text:=memo1.Text+'3';
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='4' else
memo1.text:='4';
end
else
memo1.Text:=memo1.Text+'4';
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='5' else
memo1.text:='5';
end
else
memo1.Text:=memo1.Text+'5';
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='6' else
memo1.text:='6' ;
end
else
memo1.Text:=memo1.Text+'6';
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='7' else
memo1.text:='7' ;
end
else
memo1.Text:=memo1.Text+'7';
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
if memo1.text<>'' then
if MemLogic='0' then
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='8' else
memo1.text:='8';
end
else
memo1.Text:=memo1.Text+'8';
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
if memo1.text<>'' then {jika teks dari memo1(layar) tidak kosong maka program akan menjalankan instruksi berikutnya}
if MemLogic='0' then {jika nilai dari variable MemLogic adalah 0 maka program akan menjalankan intruksi pada baris berikutnya yaitu antara kata begin dan end}
begin
MemLogic:='1';
if MemOperator<>'' then memo1.Text:='9' else {jika nilai dari variable MemOperator adalah 0 maka teks pada memo1 atau layar kalkulator menjadi 0, Mengenai maksud dari nilai variable MemOperator, juga telah dijelaskan pada bagian logika program di atas}
memo1.text:='9';
end
else
memo1.Text:=memo1.Text+'9';
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
if memo1.text<>'' then
memo1.Text:=memo1.Text + '.';
{menambahkan tanda desimal(titik) pada teks dari memo}
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
if memo1.text<>'' then
memo1.Text:=floattostr(strtofloat(memo1.Text)*(-1));
{mengubah nilai memo1 menjadi positif atau negatif}
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
if (memo1.text<>'') then
if MemLogic='0' then MemOperator:='+' else
if (MemOperator='') then
begin
MemOperator:='+';
MemLogic:='0';
MemAngka:=memo1.Text;
end
else
begin
if MemOperator='+' then memo1.Text:=floattostr(strtofloat(MemAngka)+strtofloat(memo1.Text));
if MemOperator='-' then memo1.Text:=floattostr(strtofloat(MemAngka)-strtofloat(memo1.Text));
if MemOperator='x' then memo1.Text:=floattostr(strtofloat(MemAngka)*strtofloat(memo1.Text));
if MemOperator='/' then memo1.Text:=floattostr(strtofloat(MemAngka)/strtofloat(memo1.Text));
MemAngka:=memo1.Text;
MemOperator:='+';
MemLogic:='0';
end;
end;
procedure TForm1.Button16Click(Sender: TObject);
begin
if (memo1.text<>'') then
if MemLogic='0' then MemOperator:='-' else
if (MemOperator='') then
begin
MemOperator:='-';
MemLogic:='0';
MemAngka:=memo1.Text;
end
else
begin
if MemOperator='+' then memo1.Text:=floattostr(strtofloat(MemAngka)+strtofloat(memo1.Text));
if MemOperator='-' then memo1.Text:=floattostr(strtofloat(MemAngka)-strtofloat(memo1.Text));
if MemOperator='x' then memo1.Text:=floattostr(strtofloat(MemAngka)*strtofloat(memo1.Text));
if MemOperator='/' then memo1.Text:=floattostr(strtofloat(MemAngka)/strtofloat(memo1.Text));
MemAngka:=memo1.Text;
MemOperator:='-';
MemLogic:='0';
end;
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
if (memo1.text<>'') then
if MemLogic='0' then MemOperator:='x' else
if (MemOperator='') then
begin
MemOperator:='x';
MemLogic:='0';
MemAngka:=memo1.Text;
end
else
begin
if MemOperator='+' then memo1.Text:=floattostr(strtofloat(MemAngka)+strtofloat(memo1.Text));
if MemOperator='-' then memo1.Text:=floattostr(strtofloat(MemAngka)-strtofloat(memo1.Text));
if MemOperator='x' then memo1.Text:=floattostr(strtofloat(MemAngka)*strtofloat(memo1.Text));
if MemOperator='/' then memo1.Text:=floattostr(strtofloat(MemAngka)/strtofloat(memo1.Text));
MemAngka:=memo1.Text;
MemOperator:='x';
MemLogic:='0';
end;
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
if (memo1.text<>'') then
if MemLogic='0' then MemOperator:='/' else
if (MemOperator='') then
begin
MemOperator:='/';
MemLogic:='0';
MemAngka:=memo1.Text;
end
else
begin
if MemOperator='+' then memo1.Text:=floattostr(strtofloat(MemAngka)+strtofloat(memo1.Text));
if MemOperator='-' then memo1.Text:=floattostr(strtofloat(MemAngka)-strtofloat(memo1.Text));
if MemOperator='x' then memo1.Text:=floattostr(strtofloat(MemAngka)*strtofloat(memo1.Text));
if MemOperator='/' then memo1.Text:=floattostr(strtofloat(MemAngka)/strtofloat(memo1.Text));
MemAngka:=memo1.Text;
MemOperator:='/';
MemLogic:='0';
end;
end;
procedure TForm1.Button17Click(Sender: TObject);
begin
if MemOperator='+' then memo1.Text:=floattostr(strtofloat(MemAngka)+strtofloat(memo1.Text));
if MemOperator='-' then memo1.Text:=floattostr(strtofloat(MemAngka)-strtofloat(memo1.Text));
if MemOperator='x' then memo1.Text:=floattostr(strtofloat(MemAngka)*strtofloat(memo1.Text));
if MemOperator='/' then memo1.Text:=floattostr(strtofloat(MemAngka)/strtofloat(memo1.Text));
MemAngka:=memo1.Text;
MemLogic:='0';
end;
procedure TForm1.Button20Click(Sender: TObject);
begin
if memo1.text<>'' then
memo1.Text:=floattostr(sqrt(strtofloat(memo1.Text)));
end;
end.
Selamat mencoba, semoga bermanfaat
No comments:
Post a Comment
Silahkan masukkan komentar sobat, komentar sobat sangat berarti buat saya