Edit Update Delete Di Lazarus

Memulai belajar pemrograman dengan Lazarus yang berbasis Pascal. Sebagai contoh saya membuat aplikasi laporan harian IT. Seperti dibawah ini.
lazarus
Membuat Procedure
procedure tampilkan();

procedure TForm1.tampilkan();
begin
edtNama.text:=SQLQuery1nama.AsString;
edtKasus.text:=SQLQuery1kasus.AsString;
edtPeny.text:=SQLQuery1penyelesaian.AsString;
edtStatus.Text:=SQLQuery1status.AsString;
end;

procedure kolombersih();

procedure TForm1.kolombersih();
begin
edtNama.text:=”;
edtNama.Text:=”;
edtKasus.Text:=”;
edtpeny.Text:=”;
edtStatus.Text:=”;
end;

Kode Button Tambah

kolombersih();
edtNama.Enabled:=true;
edtNama.SetFocus;
btnTambah.Enabled:=false;
btnhapus.Enabled:=false;
btnAktifkan.Enabled:=false;
btnUbah.Enabled:=false;
btnKeluar.Enabled:=false;
btnBatal.Enabled:=true;
btnSimpan.Enabled:=true;
btnSimpan.Visible:=true;
btnSimpan2.Enabled:=false;
btnPri.Enabled:=false;

Kode Button Ubah

tampilkan;
edtNama.SetFocus;
btnTambah.Enabled:=false;
btnUbah.Enabled:=False;
btnhapus.Enabled:=False;
btnSimpan.Enabled:=false;
btnSimpan.Visible:=false;
btnSimpan2.Enabled:=true;
btnSimpan2.Visible:=true;
btnBatal.Enabled:=true;
btnBatal.Visible:=True;
btnKeluar.Enabled:=false;
btnAktifkan.Enabled:=false;
edtNama.Text:=SQLQuery1.FieldByName(‘nama’).AsString;
edtKasus.Text:=SQLQuery1.FieldByName(‘kasus’).AsString;
edtpeny.Text:=SQLQuery1.FieldByName(‘penyelesaian’).AsString;
edtStatus.Text:=SQLQuery1.FieldByName(‘status’).AsString;

Kode Button Hapus

No:=IntToStr(SQLQuery1.FieldValues[‘No’]);
SQLQuery2.SQL.Clear;
SQLQuery2.SQL.Add(‘delete from user where No=”‘+No+'” ‘);
SQLQuery2.ExecSQL;
ShowMessage(‘Data akan dihapus’);
SQLQuery1.Refresh;

Kode Button Simpan 1

SQLQuery1.Insert;
SQLQuery1nama.Value:=edtNama.text;
SQLQuery1kasus.Value:=edtKasus.text;
SQLQuery1penyelesaian.Value:=edtPeny.Text;
SQLQuery1status.Value:=edtStatus.Text;
SQLQuery1.Post;
SQLQuery1.ApplyUpdates();
SQLQuery1.Refresh;

Kode Button Simpan 2

No:=IntToStr(SQLQuery1.FieldValues[‘No’]);
SQLQuery2.SQL.Clear;
SQLQuery2.SQL.Add(‘update user set nama=”‘+edtNama.text+'”,kasus=”‘+edtKasus.text+'”,penyelesaian=”‘+edtPeny.Text+'”,status=”‘+edtStatus.Text+'” where No=”‘+No+'”‘);
SQLQuery2.ExecSQL;
ShowMessage(‘Data Berhasil Diubah’);
btnTambah.Enabled:=true;
btnTambah.Visible:=true;
btnubah.Enabled:=true;
btnubah.Visible:=true;
btnhapus.Enabled:=true;
btnhapus.Visible:=true;
btnSimpan.Enabled:=false;
btnSimpan2.Enabled:=false;
btnBatal.Enabled:=true;
btnAktifkan.Enabled:=false;
SQLQuery1.Refresh;

Kode Button Batal

kolombersih;
btnTambah.Enabled:=true;
btnUbah.Enabled:=true;
btnhapus.Enabled:=true;
btnSimpan.Enabled:=true;
btnKeluar.Enabled:=true;
btnBatal.Enabled:=true;
btnAktifkan.Enabled:=false;

Kode Button Keluar

close;

Kode Button Print

ShowMessage(‘Tampilkan Report’);
frmRpt.RLReport1.Preview();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s