OBYEK COMBO BOX Pemrograman Visual
Jan 13, 2016
OBYEK COMBO BOXPemrograman Visual
ComboBox digunakan untuk menampilkan daftar pilihan yang ditampilkan berbentuk kombinasi antara listbox dan edit.
Pengguna dapat mengisi data dalam kotak Edit atau memilih sesuai dengan daftar yang ada.
Daftar pilihan terdapat pada properti ITEMS. Dan pilihan yang dipilih oleh user dapat diakses melalui properti TEXT atau ITEMINDEX.
Contoh 1:
Hasil Tampilan Form
Listing Programprocedure TForm1.Button1Click(Sender: TObject);begin if Combobox1.Text='Mempawah' then edit1.Text:='20000' else if combobox1.Text='Singkawang' then edit1.Text:='75000' else if combobox1.Text='Sanggau' then edit1.Text:='85000' else edit1.Text:='0';end;
Contoh 2:
Tampilan Form
Listing Program
procedure TForm1.Button1Click(Sender: TObject);
Var
pjng, lbr, luas,konversi, konversiM, konversiCM : real;
begin
pjng:=strtofloat(edit2.Text);
lbr:=strtofloat(edit3.Text);
luas:=pjng*lbr;
if combobox1.Text ='M' then
edit4.Text:=floattostr(luas) + ' m'
else
edit4.Text:=floattostr(luas)+' cm';
//Menghitung Konversi
konversiM:=luas*100;
konversiCM:=luas/100;
if combobox1.Text ='M' then
edit1.Text:=floattostr(konversiM) + ' cm'
else
edit1.Text:=floattostr(konversiCM)+' m';
end;
Contoh 3
Tampilan Form
Listing Program
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if combobox1.Text = 'Direktur' then
edit2.Text:='5000000'
else
if combobox1.Text = 'Manager' then
edit2.Text:='3000000'
else
edit2.Text:='1000000';
end;
procedure TForm1.RadioButton1Click(Sender: TObject);
var gapok,tunj:real;
begin
if radiobutton1.Checked=true then
gapok:=strtofloat(edit2.Text);
tunj:=gapok*0.3;
edit3.Text:=floattostr(tunj);
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
var gapok,tunj:real;
begin
if radiobutton2.Checked=true then
gapok:=strtofloat(edit2.Text);
tunj:=gapok*0.1;
edit3.Text:=floattostr(tunj);
end;
procedure TForm1.Button1Click(Sender: TObject);
var pokok,tunj,bersih : real;
begin
pokok:=strtofloat(edit2.Text);
tunj:=strtofloat(edit3.Text);
bersih:=pokok+tunj;
edit4.Text:=floattostr(bersih);
end;