Entri Populer

Selasa, 19 April 2011

Tutorial Delphi


PERTEMUAN 1













procedure TForm1.btampilClick(Sender: TObject);
begin
lnama.Caption :='Uz
umaki Naruto';
lalmt.Caption :='Jl.Konoha no 30';
eumur.Text :='12';

end;

procedure TForm1.bbersihClick(Sender: TObject);
begin
lnama.Caption :='';
lalmt.Caption :='';
eumur.Text :='';
end;

procedure TForm1.bcloseClick(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
label2.Caption :='Nama Saya';
label4.caption:='Alamat';
label6.Caption :='Umur';
end;





PERTEMUAN 2






















var nil1,nil2:real;
tambah,kurang,bagi,kali:real;

procedure TForm2.cmdcloseClick(Sender: TObject);
begin
MessageDlg('Keluar?',mtError,[mbok],0);
close;
end;

procedure TForm2.cmdtambahClick(Sender: TObject);
begin
nil1:=strtofloat(enil1.Text);
nil2:=strtofloat(enil2.Text);
tambah:=nil1+nil2;
etambah.Text :=floattostr(tambah);
end;

procedure TForm2.cmdkurangClick(Sender: TObject);
begin
nil1:=strtofloat(enil1.Text);
nil2:=strtofloat(enil2.Text);
kurang:=nil1-nil2;
ekurang.Text :=floattostr(kurang);
end;

procedure TForm2.cmdbagiClick(Sender: TObject);
begin
nil1:=strtofloat(enil1.Text);
nil2:=strtofloat(enil2.Text);
bagi:=nil1/nil2;
ebagi.Text :=floattostr(bagi);
end;

procedure TForm2.cmdkaliClick(Sender: TObject);
begin
nil1:=strtofloat(enil1.Text);
nil2:=strtofloat(enil2.Text);
kali:=nil1*nil2;
ekali.Text :=floattostr(kali);
end;

end.






PERTEMUAN 3











procedure TForm3.cmdnewClick(Sender: TObject);
begin
eabsen.Text  :='';
etugas.Text  :='';
euts.Text  :='';
euas.Text  :='';
erata.Text  :='';
eabsen.SetFocus ;
end;

procedure TForm3.cmdprosesClick(Sender: TObject);
var uas,uts,tugas,absen,rata:real;
begin
uas:=StrToFloat(euas.Text );
uts:=StrToFloat(euts.Text );
tugas:=StrToFloat(etugas.Text );
absen:=StrToFloat(eabsen.Text );
rata:=(0.1*absen)+(0.2*tugas)+(0.3*uts)+(0.4*uas);
erata.Text :=FloatToStr (rata);
end;

procedure TForm3.cmdexitClick(Sender: TObject);
begin
if(application.MessageBox('Keluar?','Info',MB_YESNO  )=IDYES  )then
close;
end;

end.


















PERTEMUAN 4






procedure TForm4.cmdlagiClick(Sender: TObject);
begin
close;
end;

procedure TForm4.cmdisiClick(Sender: TObject);
begin
enama.Text :='';
cmbjab.Text :='Jabatan';
egaber.Text :='0';
egapok.Text :='0';
etunj.Text :='0';
opttetap.Checked :=false;
opthonorer.Checked :=false;
enama.SetFocus ;
end;


procedure TForm4.FormCreate(Sender: TObject);
begin
cmbjab.Items.Add('Direktur');
cmbjab.Items.Add('Manager');
cmbjab.Items.Add('Karyawan');
end;

procedure TForm4.cmbjabClick(Sender: TObject);
begin
if cmbjab.Text ='Direktur'then
egapok.Text:='500000'
else
if cmbjab.Text ='Manager' then
egapok.Text :='200000'
else
if cmbjab.Text ='Karyawan' then
egapok.Text :='1000000'

else
egapok.Text :='0'
end;

procedure TForm4.opttetapClick(Sender: TObject);
var a,hasil:real;
begin
if opttetap.Checked =true then
a:=StrToFloat(egapok.Text );
hasil:=a*0.3;
etunj.Text :=FloatToStr(hasil);
end;

procedure TForm4.opthonorerClick(Sender: TObject);
var a,hasil:real;
begin
if opthonorer.Checked =true then
a:=StrToFloat(egapok.Text );
hasil:=a*0.1;
etunj.Text :=FloatToStr(hasil);
end;

procedure TForm4.cmdtotalClick(Sender: TObject);
var a,b,c:real;
begin
a:=StrToFloat(egapok.Text );
b:=StrToFloat(etunj.Text );
c:=a+b;
egaber.Text :=FloatToStr  (c);
end;

end.








PERTEMUAN 5








implementation

{$R *.dfm}
var tulis,praktek,a,b,c,d,e,f,g:real;

procedure TForm5.epraktekKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
praktek:=StrToFloat(epraktek.Text );
a:=praktek*0.6;
e60.Text :=FloatToStr(a);
c:=a+b;
emurni.Text :=FloatToStr(c);
if c >=60 then
egrade.Text :='Lulus'
else
egrade.Text :='Gagal'
end;

procedure TForm5.etulisKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
tulis:=StrToFloat(etulis.Text );
b:=tulis*0.4;
e40.Text :=FloatToStr(b);
end;

procedure TForm5.cmiClick(Sender: TObject);
begin
if cmi.Checked =true then
emi.Text :='250000'
else
emi.Text :='0'
end;

procedure TForm5.ctkClick(Sender: TObject);
begin
if ctk.Checked =true then
etk.Text :='300000'
else
etk.Text :='0'
end;

procedure TForm5.optpagiClick(Sender: TObject);
begin
if optpagi.Checked =true then
ewaktu.Text :='500000'
else
ewaktu.Text :='0'
end;

procedure TForm5.optsoreClick(Sender: TObject);
begin
if optsore.Checked =true then
ewaktu.Text :='1000000'
else
ewaktu.Text :='0'
end;

procedure TForm5.cmdtotalClick(Sender: TObject);
begin
d:=StrToFloat(emi.Text );
e:=StrToFloat(etk.Text );
f:=StrToFloat(ewaktu.Text );
g:=d+e+f;
etotal.Text :=FloatToStr(g);
end;

procedure TForm5.cmdcloseClick(Sender: TObject);
begin
close;
end;

procedure TForm5.cmdisiClick(Sender: TObject);
begin
etulis.Text :='';
epraktek.Text :='';
emurni.Text :='';
e40.Text :='';
e60.Text :='';
egrade.Text :='';
emi.Text :='';
etk.Text :='';
ewaktu.Text :='';
etotal.Text :='';
cmi.Checked:=false;
ctk.Checked:=false;
optpagi.Checked:=false;
optsore.Checked:=false;
end;

end.


PERTEMUAN 6




private
    { Private declarations }
  public
    { Public declarations }
    procedure bersih;
  end;

var
  Form6: TForm6;

implementation

uses Math;
procedure TForm6.bersih;
begin
enapem.Text:='';
enapes.Text :='';
ehrgd.Text :='';
ehrga.Text:='';
ejumd.Text:='';
ejuma.Text:='';
ettld.Text:='';
ettla.Text:='';
ejumtik.Text:='';
etobay.Text:='';
ebayar.Text:='';
ekembali.Text:='';
cmbnopes.Text:='';
end;

{$R *.dfm}
var hrgd,hrga,jumd,juma,ttld,ttla,jumtik,tobay,bayar,kembali:real;

procedure TForm6.cmdisiClick(Sender: TObject);
begin
bersih;
end;

procedure TForm6.cmdcloseClick(Sender: TObject);
begin
close;
end;

procedure TForm6.FormCreate(Sender: TObject);
begin
DateSeparator:='-';
ShortDateFormat :='mm/dd/yyyy';
etanggal.Text :=DateToStr(Date);
ejam.Text :=TimeToStr(time);
end;

procedure TForm6.cmdkeluarClick(Sender: TObject);
begin
if (Application.MessageBox('Mau Keluar','Info',MB_YESNO )=IDYES) then
close;
end;

procedure TForm6.cmbnopesClick(Sender: TObject);
begin
if cmbnopes.Text ='GI733' then
enapes.Text:='Garuda Air'
else if cmbnopes.Text ='MP373' then
enapes.Text:='Merpati Air'
else
enapes.Text:='Bouraq Air';
if cdewasa.Checked =true then
  begin
  if cmbnopes.Text = 'GI733' then
  ehrgd.Text:='560000'
  else
  if cmbnopes.Text = 'MP373' then
  ehrgd.Text:='450000'
  else
  ehrgd.Text:='360000'
  end
else
ehrgd.Text:='0';
if canak.Checked =true then
  begin
  if cmbnopes.Text = 'GI733' then
  ehrga.Text:='460000'
  else
  if cmbnopes.Text = 'MP373' then
  ehrga.Text:='350000'
  else
  ehrga.Text:='260000'
  end
else
ehrga.Text:='0';
end;

procedure TForm6.canakClick(Sender: TObject);
begin
if canak.Checked =true then
  begin
  if cmbnopes.Text = 'GI733' then
  ehrga.Text:='460000'
  else
  if cmbnopes.Text = 'MP373' then
  ehrga.Text:='350000'
  else
  ehrga.Text:='260000'
  end
else
ehrga.Text:='0';
ejuma.SetFocus;
end;

procedure TForm6.ejumaChange(Sender: TObject);
begin
hrga:=StrToFloat(ehrga.Text );
juma:=StrToFloat(ejuma.Text );
ttla:=hrga*juma ;
ettla.Text:=FloatToStr(ttla);

end;

procedure TForm6.ejumdChange(Sender: TObject);
begin
hrgd:=StrToFloat(ehrgd.Text );
jumd:=StrToFloat(ejumd.Text );
ttld:=hrgd*jumd ;
ettld.Text:=FloatToStr(ttld);
end;

procedure TForm6.cmdprosesClick(Sender: TObject);
begin
jumd:=StrToFloat(ejumd.Text );
juma:=StrToFloat(ejuma.Text );
jumtik:=jumd+juma ;
ejumtik.Text:=FloatToStr(jumtik);
ttld:=StrToFloat(ettld.Text );
ttla:=StrToFloat(ettla.Text );
tobay:=ttld+ttla;
etobay.Text:=FloatToStr(tobay);
ebayar.setfocus;
end;

procedure TForm6.cmdbersihClick(Sender: TObject);
begin
bersih;
end;

procedure TForm6.ebayarKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
tobay:=StrToFloat(etobay.Text );
bayar:=StrToFloat(ebayar.Text );
kembali:=bayar-tobay;
ekembali.Text:=FloatToStr(kembali );
 end
end;

procedure TForm6.cdewasaClick(Sender: TObject);
begin
if cdewasa.Checked =true then
  begin
  if cmbnopes.Text = 'GI733' then
  ehrgd.Text:='560000'
  else
  if cmbnopes.Text = 'MP373' then
  ehrgd.Text:='450000'
  else
  ehrgd.Text:='360000'
  end
else
ehrgd.Text:='0';
end;

end.
























































implementation

procedure TForm7.bersih;
begin
Memo1.Clear;
Memo2.Clear;
Memo3.Clear;
Memo4.Clear;
Memo5.Clear;
end;

procedure TForm7.nonaktif;
begin
Memo1.Enabled :=False;
Memo2.Enabled :=False;
Memo3.Enabled :=False;
Memo4.Enabled :=False;
Memo5.Enabled :=False;
end;
{$R *.dfm}
var a:integer;

procedure TForm7.cmdcontoh1Click(Sender: TObject);
begin
for a:=1 to 5 do
Memo1.Lines.Add(inttostr(a));
end;

procedure TForm7.cmdcontoh2Click(Sender: TObject);
begin
for a:=5 downto 1 do
Memo2.Lines.Add(inttostr(a));
end;

procedure TForm7.Button1Click(Sender: TObject);
begin
a:=0;
while a <5 do
begin
Memo3.Lines.Add(inttostr(a));
a:=a+1;
end;
end;

procedure TForm7.cmdcontoh4Click(Sender: TObject);
begin
a:=1;
repeat
a:=a+2;
Memo4.Lines.Add(inttostr(a));
until a=13;
end;

procedure TForm7.Button2Click(Sender: TObject);
begin
close;
end;

procedure TForm7.Button3Click(Sender: TObject);
begin
bersih;
end;

procedure TForm7.Button4Click(Sender: TObject);
var b:char;
begin
for b:='a' to 'e' do
Memo5.Lines.Add(b);
end;

procedure TForm7.FormActivate(Sender: TObject);
begin
nonaktif ;
end;

end.



Tidak ada komentar:

Poskan Komentar