LISTING PROGRAM
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1:
TButton;
Button2:
TButton;
Button3:
TButton;
Button4:
TButton;
Button5:
TButton;
Edit3: TEdit;
procedure Button1Click(Sender:
TObject);
procedure Button2Click(Sender:
TObject);
procedure Button3Click(Sender:
TObject);
procedure Button4Click(Sender:
TObject);
procedure Button5Click(Sender:
TObject);
private
{ Private declarations
}
public
{ Public declarations
}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c : integer;
begin
a := strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a + b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a - b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
a,b : integer;
c : real;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a/b;
Edit3.Text :=
floattostr(c);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a * b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
end;
end.
|
LOGIKA PROGRAM
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1:
TButton;
procedure Button1Click(Sender:
TObject);
private
{ Private declarations
}
public
{ Public declarations
}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c : integer;
begin
a := strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a + b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a - b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
a,b : integer;
c : real;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a/b;
Edit3.Text :=
floattostr(c);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a * b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
end;
end.
|
Berikutnya adalah menulis program pada button
perhitungan aritmatik agar button nya berfungsi. Yang pertama adalah BUTTON TAMBAH (+). Ketika menulis
program pada delphi selalu diawali dengan kata “procedure”, kemudian mendeklarasikan variabel yang akan kita
gunakan, serta jenis variabel nya var a,
b, c : integer; , kemudian mulai menuliskan program perhitungannya ,
diawali dengan kata begin dan
diakhiri dengan end;. Selanjutnya
ada strtoint yang fungsi nya untuk
merubah type data string menjadi integer.
procedure TForm1.Button2Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a - b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
a,b : integer;
c : real;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a/b;
Edit3.Text :=
floattostr(c);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a * b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
end;
end.
|
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c : integer;
begin
a := strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a + b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a - b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
a,b : integer;
c : real;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a/b;
Edit3.Text :=
floattostr(c);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a * b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
end;
end.
|
Selanjutnya kita membuat BUTTON Kali dan Bagi. Sama
juga seperti button tambah dan kurang. Yang membedakan hanya operator aritmatik
nya saja.
procedure TForm1.Button3Click(Sender: TObject);
var
a,b : integer;
c : real;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a/b;
Edit3.Text :=
floattostr(c);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
a,b,c : integer;
begin
a :=
strtoint(Edit1.Text);
b :=
strtoint(Edit2.Text);
c := a * b;
Edit3.Text :=
inttostr(c);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
end;
end.
|
procedure TForm1.Button5Click(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
end;
end.
|
OUTPUT PROGRAM