Kali ini Mr. Didik akan menambah posting tentang Delphi...
Langsung saja ini dia :
Pertama design dulu tampilannya sbb :
Habis itu, masukan list pilihan dari combo box :
Selanjutnya, untuk membuat prosedur yang public, cari kode :
public
{ Public declarations }
lalu masukan kode berikut di bawah kode public:
procedure bersih();
procedure aktif();
procedure nonaktif();
Then, ini dia coding-nya :
procedure tform6.bersih();
begin
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit4.Clear;
edit5.Clear;
edit6.Clear;
edit7.Clear;
edit8.Clear;
combobox1.Text:='Pilih Kode';
radiobutton1.Checked:=false;
radiobutton2.Checked:=false;
end;
procedure tform6.nonaktif();
begin
edit1.Enabled:=false;
edit2.Enabled:=false;
edit3.Enabled:=false;
edit4.Enabled:=false;
edit5.Enabled:=false;
edit6.Enabled:=false;
edit7.Enabled:=false;
edit8.Enabled:=false;
combobox1.Enabled:=false;
radiobutton1.Enabled:=false;
radiobutton2.Enabled:=false;
button1.Enabled:=false;
end;
procedure tform6.aktif();
begin
edit1.Enabled:=true;
edit2.Enabled:=true;
edit3.Enabled:=true;
edit4.Enabled:=true;
edit5.Enabled:=true;
edit6.Enabled:=true;
edit7.Enabled:=true;
edit8.Enabled:=true;
combobox1.Enabled:=true;
radiobutton1.Enabled:=true;
radiobutton2.Enabled:=true;
button1.Enabled:=true;
end;
procedure TForm6.Timer1Timer(Sender: TObject);
begin
label1.Caption:=datetostr(date());
label2.Caption:=timetostr(time());
end;
procedure TForm6.FormActivate(Sender: TObject);
begin
bersih();
nonaktif();
button2.SetFocus
end;
procedure TForm6.Button2Click(Sender: TObject);
begin
aktif();
bersih();
combobox1.SetFocus;
end;
procedure TForm6.ComboBox1Click(Sender: TObject);
begin
if combobox1.Text='SMS01' then
begin
edit1.Text:='Samsung Televisi';
edit2.Text:='2000000';
end else
if combobox1.Text='LG01' then
begin
edit1.Text:='LG Televisi';
edit2.Text:='2500000';
end else
begin
edit1.Text:='Toshiba Televisi';
edit2.Text:='3000000';
end;
end;
procedure TForm6.RadioButton1Click(Sender: TObject);
var a,b : real;
begin
if radiobutton1.Checked=true then
begin
a:=strtofloat(edit2.Text);
b:=a*0.5;
edit3.Text:=floattostr(b);
end else
begin
a:=strtofloat(edit2.Text);
b:=a*0.1;
edit3.Text:=floattostr(b);
end;
edit4.SetFocus;
end;
procedure TForm6.RadioButton2Click(Sender: TObject);
var a,b : real;
begin
if radiobutton2.Checked=true then
begin
a:=strtofloat(edit2.Text);
b:=a*0.1;
edit3.Text:=floattostr(b);
end else
begin
a:=strtofloat(edit2.Text);
b:=a*0.5;
edit3.Text:=floattostr(b);
end;
edit4.SetFocus;
end;
procedure TForm6.Edit4KeyPress(Sender: TObject; var Key: Char);
var a,b,c,d : real;
begin
if Key=chr(13) then
begin
a:=strtofloat(edit2.Text);
b:=strtofloat(edit3.Text);
c:=strtofloat(edit4.Text);
d:=(a-b)*c;
edit5.Text:=floattostr(d);
button1.SetFocus;
end;
end;
procedure TForm6.Edit7KeyPress(Sender: TObject; var Key: Char);
var a,b,c : real;
begin
if Key=chr(13) then
begin
a:=strtofloat(edit6.Text);
b:=strtofloat(edit7.Text);
c:=b-a;
if c<0 then
begin
application.MessageBox('Uang Bayar kurang!','Warning',MB_OK);
edit7.Clear;
edit7.SetFocus;
end else
begin
edit8.Text:=floattostr(c);
showmessagefmt('Terima kasih. Kembalian Anda Rp %f',[c]);
nonaktif();
button2.SetFocus;
end;
end;
end;
procedure TForm6.Button1Click(Sender: TObject);
var a : real;
begin
a:=strtofloat(edit5.Text);
edit6.Text:=floattostr(a);
edit7.SetFocus;
end;
procedure TForm6.Button3Click(Sender: TObject);
begin
if (application.MessageBox('Close Window?','Exit',MB_YESNO)=IDYES) then
close;
end;
Apabila kode yang di masukan benar, berarti hasil running program adalah sebagai berikut:
OK, sekian dulu!
Semoga bermanfaat.
Correct Me If I Wrong!
Thx






sering sering ya dik
BalasHapusmksh didik,
BalasHapus