BORLAND DELPHI DAN APLIKASINYA, oleh Ketut Udy Ariawan, S.T., M.T. Hak Cipta © 2014 pada penulis GRAHA ILMU Ruko Jambusari 7A Yogyakarta 55283 Telp: 0274-889398; Fax: 0274-889057; E-mail:
[email protected] Hak Cipta dilindungi undang-undang. Dilarang memperbanyak atau memindahkan sebagian atau seluruh isi buku ini dalam bentuk apa pun, secara elektronis maupun mekanis, termasuk memfotokopi, merekam, atau dengan teknik perekaman lainnya, tanpa izin tertulis dari penerbit. ISBN: 978-602-262-381-6 Cetakan Pertama, tahun 2014
Semua informasi tentang buku ini, silahkan scan QR Code di cover belakang buku ini
Borland Delphi dan Aplikasinya
KATA PENGANTAR
A
tas asung kertha wara nugraha Ida Sang Hyang Widhi Wasa/Tuhan Yang Maha Esa sehingga atas karunia-Nya penulis dapat menyelesaikan buku ini sesuai dengan rencana. Tujuan penulisan buku ini adalah untuk menambah pengetahuan dalam pembelajaran Bahasa Pemrograman Tingkat Tinggi. Penulis berharap semoga buku ini dapat memberikan pengalaman yang berguna baik bagi pembaca, yang tentunya akan menambah ilmu dan wawasan berpikir pembaca. Terima kasih juga disampaikan kepada pihak-pihak yang telah membantu penyusunan buku ini, semoga buku ini dapat berguna bagi para pembaca khususnya, maupun bagi masyarakat pada umumnya. Penulis menyadari bahwa buku ini masih jauh dari sempurna, oleh karena itu kritik dan saran dari semua pihak yang bersifat membangun selalu kami harapkan demi kesempurnaan penulisan selanjutnya.
Singaraja, Nopember 2014
Penulis
vi
Borland Delphi dan Aplikasinya
Borland Delphi dan Aplikasinya
DAFTAR ISI
KATA PENGANTAR ................................................................................................................
v
DAFTAR ISI ............................................................................................................................
vii
DAFTAR GAMBAR .................................................................................................................
xi
DAFTAR TABEL ....................................................................................................................
xvii
BAB I
PENGENALAN DELPHI ....................................................................................... 1.1 Pengertian Delphi ........................................................................................ 1.2 OOP (Object Oriented Programming) .......................................................... 1.3 Delphi dan OOP (Object Oriented Programming) ........................................ 1.4 IDE Delphi ................................................................................................... Soal Latihan : Aplikasi Salam Kenal .......................................................................
1 1 2 3 3 10
BAB II
OPERATOR, DEKLARASI, TIPE DATA DAN MENGENAL OBJECT I ...................... 2.1 Deklarasi ...................................................................................................... 2.1.1 Deklarasi Konstanta............................................................................ 2.1.2 Deklarasi Variabel .............................................................................. 2.2 Tipe Data ..................................................................................................... 2.2.1 Tipe Data Numeric Integer ................................................................. 2.2.2 Tipe Data Real ................................................................................... 2.2.3 Tipe Data String ................................................................................. 2.2.4 Tipe Data Char ................................................................................... 2.3 Dasar Umum Merancang Program Aplikasi Berbasis Visual .......................... 2.4 Mengenal Komponen Label, Edit & Button ...................................................
13 13 13 14 14 14 15 15 15 15 16
viii
Borland Delphi dan Aplikasinya
2.5 Mengenal Operator ...................................................................................... 2.5.1 Operator Penugasan (Assignment Operator) ....................................... 2.5.2 Operator Aritmatika ........................................................................... 2.5.3. Operator String .................................................................................. 2.5.4. Merancang Aplikasi dengan Delphi .................................................... Soal Latihan : Program Pembayaran ......................................................................
16 16 16 17 17 21
PERCABANGAN DAN MENGENAL OBJECT II (COMBO BOX, RADIO BUTTON) .......................................................................................................... 3.1 Operator Percabangan .................................................................................. 3.1.1 Percabangan If ................................................................................... 3.1.2 Percabangan Case .............................................................................. 3.2 Mengenal Object II (Combo Box, List Box dan Radio Button) ....................... 3.3 Merancang Program dengan Fungsi IF .......................................................... Soal Latihan: Program Biaya Ujian ........................................................................
23 23 23 24 25 26 31
BAB IV
PROSEDUR, PERULANGAN DAN MENGENAL INPUT........................................ 4.1 Prosedur ....................................................................................................... 4.2 Perulangan ................................................................................................... 4.3 Mengenal Input Box ..................................................................................... 4.4 Study Kasus Perulangan ................................................................................ Soal Latihan: Aplikasi Konversi Suhu ....................................................................
33 33 35 37 38 41
BAB V
FUNGSI 5.1 Pengertian Fungsi ......................................................................................... 5.2. Fungsi Tunggal .............................................................................................. 5.3 Fungsi untuk Memanggil Fungsi yang lain .................................................... Soal Latihan : Aplikasi Koperasi ............................................................................
43 44 45 45
ARRAY ................................................................................................................. 6.1 Pengertian Array ........................................................................................... 6.2 Deklarasi Array ............................................................................................ 6.3 Alokasi Penggunaan Array ............................................................................ Soal Latihan : Studi Kasus Program dengan Array ..................................................
49 49 50 51
OPERATOR STRING ........................................................................................... 7.1 Menggabungkan String ................................................................................. 7.2 Menghapus Teks .......................................................................................... 7.3 Mencari Panjang Teks (Length) ..................................................................... 7.4 Mencari Karakter pada Teks (POS) ................................................................ 7.5 Mengkopi String (Copy) ................................................................................
53 53 55 57 59 60
BAB III
BAB VI
BAB VII
ix
Daftar Isi
7.6 Konversi Karakter ke Ascii (Chr).................................................................... Soal Latihan : Konversi Suhu .................................................................................
62 62
BAB VIII
DATA BASE DESKTOP ...................................................................................... 8.1 Pengertian Data Base Desktop ...................................................................... 8.2 Langkah – Langkah pembuatan Data Base Dekstop ...................................... 8.3 Membuat Tabel ............................................................................................ 8.4 Menyimpan Tabel ........................................................................................ 8.5 Membuka Tabel ........................................................................................... 8.6 Membuat Index (Secondary Index) ............................................................... 8.7 Mengisi Data pada Tabel .............................................................................. 8.8 Membuat Alias Manager ............................................................................... Soal Latihan : ........................................................................................................
65 65 65 66 68 69 69 71 72 73
BAB IX
KOMPONEN QUERY ATAU SQL (STRUTURED QUERY LANGUAGE) ............... 9.1 Sekilas Mengenai SQL .................................................................................. 9.2 Dasar – Dasar mengenai Metode SQL .......................................................... 9.2.1 DDL (Data Defenition Language) ....................................................... 9.2.2 DML (Data Manipulation Language) ................................................... 9.2.3 Penerapan Konsep SQL pada Aplikasi ................................................ Soal Latihan : ........................................................................................................
75 75 75 75 76 79 84
BAB X
KONTROL DATA SET DAN NAVIGATOR ............................................................ 10.1 Komponen Tabel .......................................................................................... 10.2 Kontrol Tabel ............................................................................................... Soal Latihan : Merancang Program dengan Kontrol Tabel ......................................
87 87 89 89
BAB XI
PENCARIAN DATA ............................................................................................. 11.1 Konsep Pemrograman Pencarian Data .......................................................... Soal Latihan : Aplikasi Program Pencarian Data ....................................................
93 93 95
BAB XII
FILTER DAN RANGE DATA ................................................................................. 12.1 Filter .......................................................................................................... 12.2 Range .......................................................................................................... Soal Latihan : Merancang Aplikasi Program dengan Fungsi Range dan Filter .........
101 101 102 102
BAB XIII
MANIPULASI DATA/TABEL MASTER ................................................................... 13.1 Program Tambah Data .................................................................................. 13.2 Event yang Digunakan .................................................................................. 13.3 Aplikasi Tambah Data Barang ....................................................................... Soal Latihan : Aplikasi Program Edit dan Hapus Data ............................................
105 105 105 106 111
x
Borland Delphi dan Aplikasinya
BAB XIV
APLIKASI FORM FILE TRANSAKSI (PENJUALAN) ................................................. 117 14.1 Menambah Tabel Transaksi .......................................................................... 117 14.2 Aplikasi Program File Transaksi .................................................................... 118
BAB XV
QUERY DAN SQL LANJUTAN ............................................................................. 127 15.1 Aplikasi Program Hapus dan Retur Stok Barang ............................................ 128
BAB XVI
PEMBUATAN LAPORAN .................................................................................... 16.1 Membuat Laporan Data Barang .................................................................... 16.2 Mencetak Laporan melalui Form .................................................................. Soal Latihan : Sistem Informasi Toko .....................................................................
133 134 141 142
BAB XVII
INTERFACING KOMPUTER DAN MIKROKONTROLER DENGAN DELPHI .......... 17.1 Port Serial Mikrokontroler ............................................................................ 17.2 Teknik Komunikasi Serial Mikrokontroler ..................................................... 17.3 Pemrograman Komunikasi Serial .................................................................. 17.4 Pemrograman DELPHI .................................................................................. 17.5 Aplikasi Pertama: Komunikasi Serial Mikro dengan Komputer ...................... 17.6 Aplikasi Kedua: Kontrol 1 Relay ................................................................... 17.7 Aplikasi Ketiga: Kontrol 4 Relay.................................................................... 17.8 Aplikasi Keempat: Kontrol Relay Berbasis Waktu .......................................... 17.9 Aplikasi Kelima: Baca Digital Input Via Komputer ........................................
145 145 147 148 153 157 158 162 168 174
DAFTAR PUSTAKA ................................................................................................................. 183