SlideShare a Scribd company logo
1 of 4
Download to read offline
SIMPLE CRUD DENGAN LAZARUS FREE PASCAL
Persiapan Basis Data:
Hostname : localhost
Nama Database : jajalazarus
Username : lazarus
Password : laz12345
Tabel biodata
Field Type Null Key Default Extra
nomor int(2) NO PRI NULL auto_increment
nama varchar(30) NO NULL
tglahir date YES NULL
agama enum('islam','katholik','kristen','hi
ndu','buddha','kong hu cu')
YES islam
Langkah:
1. Login ke mysql server (via phpmyadmin / terminal command line) sebagai user root.
2. Pada konsol mysql atau tab sql di phpMyAdmin. Tuliskan perintah berikut secara berurut:
create database jajalazarus;
grant all on jajalazarus.* to lazarus@localhost identified by 'laz12345';
use jajalazarus;
create table biodata(
nomor int(2) not null auto_increment primary key, [enter]
nama varchar(30) not null, [enter]
tglahir date,[enter]
agama enum('islam','katholik','kristen','hindu','buddha','kong hu cu') default
'islam' );
Step 1.
Buka project baru lazarus. Tempatkan pada Form1 objek-objek sebagai berikut:
Dari tab Standard:
4 x Label
4 x Button
Dari tab Data Controls:
1 x DBText
2 x DBEdit
1 x DBComboBox
1 x DBGRid
Dari tab Data Access:
1 x DataSource
Dari tab SQLdb:
1 x MySQLxxConnection (sesuaikan xx dengan versi mysql masing-masing)
1 x SQLTransaction
1 x SQLQuery
Atur penampilan menyerupai gambar berikut:
Step 2. Pengaturan Properties (Object Inspector)
Kompoenen Label
Label Caption
Label1 Nomor
Label2 Nama
Label3 Tgl. Lahir
Label4 Agama
Komponen Button
Button Caption Name
Button1 Tambah btnTambah
Button2 Simpan btnSimpan
Button3 Hapus btnHapus
Button4 Keluar btnKeluar
Komponen MySQLxxConnection
Property Value / Nilai
DatabaseName jajalazarus
HostName localhost
Name conn
Password laz12345
Username lazarus
Connected True
Komponen SQLTransaction1
Property Value / Nilai
Database conn
Name Tran
Komponen SQLQuery1
Property Value / Nilai
Database conn
Name qry
SQL SELECT * FROM biodata
Active True
Komponen DataSource1
Property Value / Nilai
DataSet qry
Name ds
Komponen DataGrid1
Property Value / Nilai
DataSource ds
name grid
Komponen DBText dan DBEdit
Komponen datasource datafield Name
DBText ds nomor dbNomor
DBEdit1 ds nama dbNama
DBEdit2 ds tglahir dbTglahir
Komponen DBComboBox1
Property Value / Nilai
DataSource ds
DataField agama
Items islam
kristen
katholik
hindu
budhha
kong hu cu
Name dbAgama
Step 3 Penambahan Kode Program
Kode Penambahan Record melalui btnTambah. Klik 2x btnTambah. Tuliskan kode yang dicetak
tebal
procedure TForm1.btnTambahClick(Sender: TObject);
begin
ds.DataSet.Append;
end;
Kode Peyimpanan Record melalui btnSimpan. Klik 2x btnSimpan. Tuliskan kode yang dicetak
tebal
procedure TForm1.btnSimpanClick(Sender: TObject);
begin
qry.UpdateMode:=upWhereChanged;
qry.ApplyUpdates;
tran.Commit;
ds.DataSet.Active:=True;
grid.Refresh;
end;
Kode Penghapusan Record melalui btnHapus. Klik 2x btnHapus. Tuliskan kode yang dicetak
tebal.
procedure TForm1.btnHapusClick(Sender: TObject);
var
nomor,sql:string;
begin
nomor:=quotedStr(dbNomor.Caption);
sql:='DELETE FROM biodata WHERE nomor='+nomor+' Limit 1';
label5.Caption:=sql;
ds.DataSet.Active:=False;
tran.Commit;
tran.StartTransaction;
conn.ExecuteDirect(sql);
tran.CommitRetaining;
ds.DataSet.Active:=True;
grid.Refresh;
end;
Kode Menutup Program Aplikasi melalui btnKeluar. Klik 2x btnKeluar. Tuliskan Kode yang
dicetak tebal.
procedure TForm1.btnKeluarClick(Sender: TObject);
begin
application.Terminate;
end;

More Related Content

Viewers also liked

Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersKevlin Henney
 
Making Forms Accessible to all users
Making Forms Accessible to all usersMaking Forms Accessible to all users
Making Forms Accessible to all usersRyan Schroeder
 
Get your Health Care Mobile App Discovered!
Get your Health Care Mobile App Discovered!Get your Health Care Mobile App Discovered!
Get your Health Care Mobile App Discovered!TechAhead
 
Functional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerFunctional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerRaúl Raja Martínez
 
Microsoft und die Open Source Community - Leaving the death star behind
Microsoft und die Open Source Community - Leaving the death star behindMicrosoft und die Open Source Community - Leaving the death star behind
Microsoft und die Open Source Community - Leaving the death star behindChristian Heilmann
 
Composer The Right Way - 010PHP
Composer The Right Way - 010PHPComposer The Right Way - 010PHP
Composer The Right Way - 010PHPRafael Dohms
 
Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Rachel Andrew
 
Web Components for Java Developers
Web Components for Java DevelopersWeb Components for Java Developers
Web Components for Java DevelopersJoonas Lehtinen
 

Viewers also liked (9)

Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
Making Forms Accessible to all users
Making Forms Accessible to all usersMaking Forms Accessible to all users
Making Forms Accessible to all users
 
Get your Health Care Mobile App Discovered!
Get your Health Care Mobile App Discovered!Get your Health Care Mobile App Discovered!
Get your Health Care Mobile App Discovered!
 
Functional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerFunctional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic Programmer
 
What's New in Java SE 9
What's New in Java SE 9What's New in Java SE 9
What's New in Java SE 9
 
Microsoft und die Open Source Community - Leaving the death star behind
Microsoft und die Open Source Community - Leaving the death star behindMicrosoft und die Open Source Community - Leaving the death star behind
Microsoft und die Open Source Community - Leaving the death star behind
 
Composer The Right Way - 010PHP
Composer The Right Way - 010PHPComposer The Right Way - 010PHP
Composer The Right Way - 010PHP
 
Confoo: You can use CSS for that!
Confoo: You can use CSS for that!Confoo: You can use CSS for that!
Confoo: You can use CSS for that!
 
Web Components for Java Developers
Web Components for Java DevelopersWeb Components for Java Developers
Web Components for Java Developers
 

More from gopartheredbuff

More from gopartheredbuff (8)

Google hacking 2015
Google hacking 2015Google hacking 2015
Google hacking 2015
 
Output unit
Output unitOutput unit
Output unit
 
Processing unit
Processing unitProcessing unit
Processing unit
 
Pcq rt-rw-net
Pcq rt-rw-netPcq rt-rw-net
Pcq rt-rw-net
 
Mikrotik Hotspot With Queue Tree BW Management
Mikrotik Hotspot With Queue Tree BW ManagementMikrotik Hotspot With Queue Tree BW Management
Mikrotik Hotspot With Queue Tree BW Management
 
Hardware1
Hardware1Hardware1
Hardware1
 
Hardware block diagram
Hardware block diagramHardware block diagram
Hardware block diagram
 
Datastore company profile
Datastore company profileDatastore company profile
Datastore company profile
 

Simple crudlazarus

  • 1. SIMPLE CRUD DENGAN LAZARUS FREE PASCAL Persiapan Basis Data: Hostname : localhost Nama Database : jajalazarus Username : lazarus Password : laz12345 Tabel biodata Field Type Null Key Default Extra nomor int(2) NO PRI NULL auto_increment nama varchar(30) NO NULL tglahir date YES NULL agama enum('islam','katholik','kristen','hi ndu','buddha','kong hu cu') YES islam Langkah: 1. Login ke mysql server (via phpmyadmin / terminal command line) sebagai user root. 2. Pada konsol mysql atau tab sql di phpMyAdmin. Tuliskan perintah berikut secara berurut: create database jajalazarus; grant all on jajalazarus.* to lazarus@localhost identified by 'laz12345'; use jajalazarus; create table biodata( nomor int(2) not null auto_increment primary key, [enter] nama varchar(30) not null, [enter] tglahir date,[enter] agama enum('islam','katholik','kristen','hindu','buddha','kong hu cu') default 'islam' ); Step 1. Buka project baru lazarus. Tempatkan pada Form1 objek-objek sebagai berikut: Dari tab Standard: 4 x Label 4 x Button Dari tab Data Controls: 1 x DBText 2 x DBEdit 1 x DBComboBox 1 x DBGRid Dari tab Data Access: 1 x DataSource Dari tab SQLdb: 1 x MySQLxxConnection (sesuaikan xx dengan versi mysql masing-masing) 1 x SQLTransaction 1 x SQLQuery
  • 2. Atur penampilan menyerupai gambar berikut: Step 2. Pengaturan Properties (Object Inspector) Kompoenen Label Label Caption Label1 Nomor Label2 Nama Label3 Tgl. Lahir Label4 Agama Komponen Button Button Caption Name Button1 Tambah btnTambah Button2 Simpan btnSimpan Button3 Hapus btnHapus Button4 Keluar btnKeluar Komponen MySQLxxConnection Property Value / Nilai DatabaseName jajalazarus HostName localhost Name conn Password laz12345 Username lazarus Connected True
  • 3. Komponen SQLTransaction1 Property Value / Nilai Database conn Name Tran Komponen SQLQuery1 Property Value / Nilai Database conn Name qry SQL SELECT * FROM biodata Active True Komponen DataSource1 Property Value / Nilai DataSet qry Name ds Komponen DataGrid1 Property Value / Nilai DataSource ds name grid Komponen DBText dan DBEdit Komponen datasource datafield Name DBText ds nomor dbNomor DBEdit1 ds nama dbNama DBEdit2 ds tglahir dbTglahir Komponen DBComboBox1 Property Value / Nilai DataSource ds DataField agama Items islam kristen katholik hindu budhha kong hu cu Name dbAgama
  • 4. Step 3 Penambahan Kode Program Kode Penambahan Record melalui btnTambah. Klik 2x btnTambah. Tuliskan kode yang dicetak tebal procedure TForm1.btnTambahClick(Sender: TObject); begin ds.DataSet.Append; end; Kode Peyimpanan Record melalui btnSimpan. Klik 2x btnSimpan. Tuliskan kode yang dicetak tebal procedure TForm1.btnSimpanClick(Sender: TObject); begin qry.UpdateMode:=upWhereChanged; qry.ApplyUpdates; tran.Commit; ds.DataSet.Active:=True; grid.Refresh; end; Kode Penghapusan Record melalui btnHapus. Klik 2x btnHapus. Tuliskan kode yang dicetak tebal. procedure TForm1.btnHapusClick(Sender: TObject); var nomor,sql:string; begin nomor:=quotedStr(dbNomor.Caption); sql:='DELETE FROM biodata WHERE nomor='+nomor+' Limit 1'; label5.Caption:=sql; ds.DataSet.Active:=False; tran.Commit; tran.StartTransaction; conn.ExecuteDirect(sql); tran.CommitRetaining; ds.DataSet.Active:=True; grid.Refresh; end; Kode Menutup Program Aplikasi melalui btnKeluar. Klik 2x btnKeluar. Tuliskan Kode yang dicetak tebal. procedure TForm1.btnKeluarClick(Sender: TObject); begin application.Terminate; end;