Friday, December 7, 2018

Delphi : Mengenal Combo Box dan Radio Button

ComboBox
Menampilkan pilihan dalam bentuk popup

Radio Button
Digunakan untuk menentukan satu pilihan dari beberapa pilihan yang ada

Contoh Program Dengan Menggunakan ComboBox dan Radio Button

a. Hasil Program



Ketentuan Perhitungan Gaji
JABATAN
GAJI POKOK
TUNJANGAN
Tetap
Honor
Direktur
5000000
1000000
800000
Manager
4000000
800000
500000
Karyawan
2500000
500000
300000


b.  Design Form


c.  Design Properties


Object
Name
Caption
Label1
Label1
Nama Pegawai
Label2
Label2
Jabatan
Label3
Label3
Gaji Pokok
Label4
Label4
Status Karyawan
Label5
Label5
Tunjangan Lauk Pauk
Label6
Label6
Gaji Bersih
RadioButton1
RadioButton1
Tetap
RadioButton1
RadioButton1
Honor
Button1
Button1
Total Gaji
Button2
Button2
Reset
Button3
Button3
Close


Object
Name
Text
Edit1
Edit1
-
Edit2
Edit2
-
Edit3
Edit3
-
Edit4
Edit4
-



d. Listing Program

Input pilihan jabatan pada combobox
1.  Aktifkan combobox yang akan diinput (combobox1)
2.  Pada properties pilih item lalu klik tombol [...]
3.  Pada jendela String List Editor, ketikan jabatan-jabatan yang diinginkan tersebut diatas.
4.  klik OK


Tampilan Awal Form procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text:= '';
Edit2.Text:= '0';
Edit3.Text:= '0';
Edit4.Text:= '0';
Combobox1.Text:= 'Pilih salah satu';
end;

Gaji Pokok sesuai pilihan jabatan pada ComboBox
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if combobox1.Text = 'Direktur' then
edit2.Text:= '5000000'
else if combobox1.Text = 'Manager' then
edit2.Text:= '4000000'
else if combobox1.Text = 'Karyawan' then
edit2.Text:= '2500000'
else
edit2.Text:= '0'
end;

Menghitung Tunjangan Pegawai Tetap
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
if radiobutton1.Checked = true then
  if combobox1.Text = 'Direktur' then
    edit3.Text:= '1000000'
  else if combobox1.Text = 'Manager' then
    edit3.Text:= '800000'
  else
    edit3.Text:= '500000';
end;

Menghitung Tunjangan Pegawai Honor
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
if radiobutton2.Checked = true then
  if combobox1.Text = 'Direktur' then
    edit3.Text:= '800000'
  else if combobox1.Text = 'Manager' then
    edit3.Text:= '500000'
  else
    edit3.Text:= '300000';
end;

Tombol Menghitung Total Gaji
procedure TForm1.Button1Click(Sender: TObject);
var
gapok, lauk, gaji: real;
begin
gapok:= strtofloat(edit2.Text);
lauk:= strtofloat(edit3.Text);
gaji:= gapok+lauk;
edit4.Text:= floattostr(gaji);
end;

Tombol Reset
procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.Text:= '';
Edit2.Text:= '0';
Edit3.Text:= '0';
Edit4.Text:= '0';
Combobox1.Text:= 'Pilih salah satu';
end;

Tombol Close
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;

No comments:

Post a Comment