Delphi untuk pemula
1.
Mengistal dan membuka Delphi Perkembangan bahasa pemrograman berlangsung dengan pesat, mulai dari bahasa tingkat rendah (yang lebih dekat dengan hardware) seperti bahasa assembly, ataupun bahasa tingkat tinggi, seperti bahasa c dan pascal. Pada bahasa ini agak susah mengembangkannya dan membuat tampilannya menjadi menarik, apalagi bila kita menggunakan bahasa pemrograman ini dalam bentuk grafik. Perkembangan bahasa pemrograman terus berlanjut dengan dikeluarkannya Windows oleh pihak Microscoft. Pada windows diperkenalkan model OOP (Object Oriented Programming) yaitu yang lebih menampilkan kemudahan dan tampilan yang menarik (seperti window-window pada application yang sering kita gunakan , ms word). Delphi merupakan salah satu program yang berbasis pada OOP, jadi dengan bahasa delphi kita dapat membuat program-program yang menarik untuk dilihat dan fleksibel serta user Friendly. Perkembangan Delphi Borland Delphi dirilis pertama kali pada bulan Februari 1995, dan Perkembangna Delphi berjalan dari Delphi satu sampai dengan Delphi 6. Dasar pemrograman delphi dimulai ketika delphi 1 dirilis, pada perkembangan delphi 3, user sudah dapat menggunakan fasilitas networking, yang memungkinkan user untuk membuat sebuah aplikasi yang dapat menghubungkan 2 komputer melalui jaringan internet. Pada perkembangan terakhir (delphi 6) user dapat membuat sebuah aplikasi yang bisa berjalan dalam operating system Linux. Membuka Delphi untuk pertama kali Sebelum menggunakan delphi kita harus menginstal Aplikasi Delphi pada komputer kita. Untuk menginstal Delphi 3 membutuhkan kurang dari 100 Mb denngan OS minimal win 3.1 dan memory 8 Mb, untuk Delphi 5 sekitar 100-200 Mb dengan OS minimal Win 95 dan Memory min 16 Mb, dan Bila kita mnginstal Delphi 6 kita membutuhkan minimal 250 Mb, dengan OS minimal Win 95 dan memory min 32 Mb.
Setelah kita melakukan instalasi, maka kita dapat memulai program kita yang pertama. Berikut ini adalah tampilan awal bila kita menggunakan delphi 6 (gambar 1)
Berikut keterangan bagian-bagian gambar diatas :
2.
Membuat program hello
Marilah untuk pengenalan pertama kita membuat program Hello. Pada program yang pertama ini, kita akan membuat sebuah program hallo. Langkah yang harus dilakukan: 1. 2. Bukalah sebuah aplikasi baru Ambil komponen button
Besar form dapat diatur
3. Letakanlah komponen tersebut pada form dan klik 2 kali 4. pada procedure klik, tuliskan syntak berikut ini
procedure TForm1.Button1Click(Sender: TObject); begin messagedlg('hallo apa kabar',mtinformation,[mbok],0); end; 5. dan kita juga bias menambahkan syntak yang megakibatkan bila kita mgklik diluar button, maka aplikasi tersebut mengeluakan sebuah pesan procedure TForm1.FormClick(Sender: TObject); begin messagedlg('Anda menekan di luar tombol',mtwarning, [mbok],0); end; 6. Jadi program kita yang pertama.
Keterangan pada program hello1 1. Pogram ini bekerja untuk medeteksi aktivitas kita saat menekan menklik pada area suatu form. Kita akan mendapat suatu pemberitahuan bila kita mengklik pada tombol atau di luar tombol. 2. Bila kita menklik pada tombol maka akan keluar suatu form message information, dengan tambahan kalimat yang bias kita ubah2,. Berbeda halnya bila kita mengklik di luar tombol maka akan ada pemberitahuan warning. 3. Ada berbagai macam bentuk message
type TMsgDlgType = (mtCustom, mtInformation, mtWarning, mtError, mtConfirmation);
mtCustom mtInformation mtWarning mtError MtConfirmatio n
Suatu kotak message dengan caption(judul) yang dapat kita atur sendiri Suatu kotak message dengan caption Information. Suatu kotak message dengan caption Warning. Suatu kotak message dengan caption Error. Suatu kotak message dengan caption Confirm
4. [mbok] merupakan tombol yang ditampilkan pada kotak dialog tersebut. Macam-macam tombol yang bias ditampilkan adalah : (mbNone, mbOk, mbCancel, mbYes, mbNo, mbAbort, mbRetry, mbIgnore)
Untuk listing program lengkapnya: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormClick(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin messagedlg('hallo apa kabar',mtinformation,[mbok],0); end; procedure TForm1.FormClick(Sender: TObject); begin messagedlg('Anda menekan di luat tombol',mtcustom,[mbok],0); end; end. 3. Membuka dan menyimpan proyek Pada saat kita membuka delphi, maka secara otomatis Delphi akan membuka sebuah application. Application adalah sebuah proyek yang akan kita buat. Dalam sebuah proyek ini anda akan menemukan berbagai macam file. Proyek Unit Pas Unit Dfm Unit pas2 Unit Dfm2 Akan menjadi nama file application
Seperti pada bagan diatas. Dalam sebauh proyek terdapat berbbagai macam file yang diperlukan untuk membangun proyek tersebut. File-file ini bisa kita tambahkan dengan bebas, asalkan tetap dalam sebuah proyek.
Menyimpan proyek dan file Diperlukan 2 buah langkah penyimpanan pada delphi, pertama penyimapan file-file dibawah proyek, dan kedua penyimpanan proyek itu sendiri.
Simpan file Simpan proyek Simpan proyek & file Tutup sebagian Tutup file & proyek Buka proyek Buka File
Terlihat jelas pada gambar di atas. Jadi kita harus memperhatikan bagian-bagian dalam penyimpanan dan buka file atau proyek. Keterangan tiapa bagian : a. Buka file Membuka sebuah file (tidak ada hubungan atau berhubungan dengan proyek). Langkah ini diperlukan untuk me-link kan sebuah fil dengan file lain, tapi masih dalam satu proyek, atau kita juga meliha program sebelumnya dan mengkopi bagianbagian tertentu saja. b. Buka proyek Membuka sebuah proyek (*.dpr), saat membuka proyek ini, maka akan terbuka juga file utama yang berhubungan dengan proyek tersebut. Namun untuk melihat link-link yang digunakan oleh file tersebut maka kita harus membukanya secara manual dengan perintah buka file (nomor a) c. Simpan file
Menyimpan file tertentu. Perhatikan saat men-klik bagian ini, maka proyek anda belum tersimpan. d. Simpan proyek Menyimpan proyek tertentu. Daapun isi proyek merupakan data mengenai link-link file yang digunakan dalam sebuah proyek tersebut. e. Simpan proyek dan file Bila kita meng-klik bagian ini maka proyek dan file akan otomatis tersimpan dalam hardisk dengan nama file dan proyek tertentu (sudah ada). Langkah ini diperlukan saat kita mo menyimpan semua file dan proyek, sehingga sengan menekkan tombol ini, kita tidak perlu susah-suha untukmenyimpan bagian file dan proyek. f. Tutup sebagian Tombol ini berguna untuk menutup file tertentu. g. Tutup file & proyek Langkah ini penting dilakukan, saat kita menutup sebuah application. Bila kita tidak melakukan ini, maka yang tertutup hanya file saja, dan proyek tidak tertutup. Artinya jika kita belum menutup proyek dan kita membuka sebuah file tertentu, maak file itu akan berada di bwah proyek yang belum kita tutup ini. Oleh karena itu pergunakan lah tombol ini, untuk menutup seluruh program yang kita buat. Dan bila ingin membuat program baru, silahkan pilih new application. h. Exit Digunakan untuk keluar dari Delphi.
4.
Penjelasan mengenai form dan file yang digunakan delphi a. Project file Merupakan sebuah file yang berisi informasi mengenai poject fule program yang kita buat.
b. Form file Form file merupakan file yang berisi informasi mengani form yang telah kita buat.Informasi ini meliputi ukuran-ukuran dan komponen apa aja yang kita taruh dalam form. c. Data module File Data module ini berisi mengenai informasi mengenai kegunaan data module. Filenya dalam extention *.dfm d. Remote Data Module File Merupakan file yang berisi remote data module. Type file ini *.rfm e. Unit File f. Form Unit Unit Name The uses Clauses The Interface Section The Implementation Section The Inialization Section The Finalization Section
5.
Objek pascal (type data)
a. Global dan local variable Global variabel adalah suatu varibel yang kita deklarasikan saat awal, global varibel ini akan mewakili atau dapat digunakan pada seluruh procedure di bawah program keseluruhan Local variabel adalah suatu variabel yang digunakan untuk mendeklarasikan suatu variabel yang hanya digunakan dalam satu procedure saja. Penting dalam penentuan global variabel dan local variabel, sehingga kita dapat menentukan adata yang lebih optimal.
b.
If then .. else If .. then .. else merupakan fungsi percabangan, yaitu bila statement pertama sesuai/tidak sesuai maka/then akan diikuti respon berikutnya, bila statemen pertama tidak sesuai / sesuai maka akan terjadi aksi yang berbeda pula Contoh If warna = merah then berenti else jalan
c.
Case of Case of adala bentuk percabangan yang mengecek satu per satu kondisi yang dibuat. Case of lampu Merah = berenti; Hijau = jalan Kuning = pelan-pelan End; Perhatikan bahwa case of harus ditutup dengan end.
d.
Repeat until Repeat .. util merupakan procedure pengulangan. Konsepnya adalah repeat suatu statemen sampai suatu statemen itu bernilai tertentu maka pengulangan itu berhenti.
8.
Menggunakan Help File Help sangat berguna bila kita dalam kesulitan saat melakukan permrograman. Pada Delphi telah disiapkan help File yang sangat lengkap, mulai dari penggunaan bahasa pascal pada delphi, menggunaan win api (driver standar windows) sampai dengan bantuan pada pemrograman Delphi itu sendiri. Cara menggunakan Help File
Sepert pada gambar di atas, kita tinggal menekan F1 untuk mengaktifkan Help file, dan kata ingin kita tanyakan langsung tertera pada help itu dan kita akan menemukan penjelasan dari pertanyaan tersebut. 10. Mode Console Mode console digunakan bila kita tidak menggunakan form, tetapi menggunakan format seperti pascal, dalam bentuk dos. Adapun untuk mengubah mode normal ke dalam mode console, anda tinggal klik 11. Komponen 12. Fungsi waktu a. 13. Pengantar Grafik dan tabel
Editor (Default)
See also
These editor keyboard shortcuts apply to the Default keystroke mapping scheme. Shortcut F1 Action or command
Help|Topic Search Help|Topic Search
Ctrl+F1 F3
Search|Search Again Search|Incremental Search Search|Find
Ctrl+E Ctrl+F
Ctrl+I Inserts a tab character Ctrl+j Templates pop-up menu Ctrl+N Ctrl+P sequence Ctrl+R Ctrl+S Ctrl+T Ctrl+Y Ctrl+Z Inserts a new line Causes next character to be interpreted as an ASCII Search|Replace File|Save Deletes a word Deletes a line Edit|Undo Code Completion pop-up window
Ctrl+ Ctrl+Shift+g
Inserts a new Globally Unique Identifier (GUID)
Ctrl+Shift+IIndents block
Ctrl+Shift+U Ctrl+Shift+Y Ctrl+Shift+Z
Outdents block Deletes to the end of a line Edit|Redo Code Parameters pop-up window
Ctrl+Shift+
Alt+[ Finds the matching delimiter (forward) Alt+] Finds the matching delimiter (backward) End Moves to the end of a line Home Moves to the start of a line
Enter Inserts a carriage return Ins Del Turns insert mode on/off Deletes the character to the right of the cursor
Backspace Deletes the character to the left of the cursor Tab Inserts a tab
SpaceInserts a blank space Left Arrow Moves the cursor left one column, accounting for the autoindent setting Right Arrow Moves the cursor right one column, accounting for the autoindent setting Up Arrow Moves up one line
Down ArrowMoves down one line Page Up Moves up one page
Page Down Moves down one page
Ctrl+Left Arrow
Moves one word left
Ctrl+Right Arrow Moves one word right Ctrl+Tab Moves to the next code page (or file) Moves to the previous code page (or file) Deletes the word to the right of the cursor
Ctrl+Shift+Tab Ctrl+Backspace
Ctrl+Home Moves to the top of a file Ctrl+End Moves to the end of a file
Ctrl+Del
Deletes a currently selected block
Ctrl+Space Inserts a blank space Ctrl+PgDn Moves to the bottom of a screen Ctrl+PgUp Moves to the top of a screen Ctrl+Up Arrow Scrolls up one line
Ctrl+Down Arrow Scrolls down one line Ctrl+Enter Opens file at cursor
Shift+Tab
Moves the cursor to the left one tab position
Shift+Backspace Deletes the character to the left of the cursor Shift+Left Arrow Selects the character to the left of the cursor
Shift+Right Arrow Selects the character to the right of the cursor Shift+Up Arrow Moves the cursor up one line and selects from the left of the starting cursor position Shift+Down Arrow Moves the cursor down one line and selects from the right of the starting cursor position Shift+PgUp Moves the cursor up one screen and selects from the left of the starting cursor position
Shift+PgDn Moves the cursor down one line and selects from the right of the starting cursor position
Shift+End line
Selects from the cursor position to the end of the current
Shift+HomeSelects from the cursor position to the start of the current line Shift+Space Inserts a blank space
Shift+Enter Inserts a new line with a carriage return
Ctrl+Shift+Left Arrow
Selects the word to the left of the cursor
Ctrl+Shift+Right Arrow Selects the word to the right of the cursor Ctrl+Shift+Home Selects from the cursor position to the start of the current file
Ctrl+Shift+End current file
Selects from the cursor position to the end of the
Ctrl+Shift+PgDn Selects from the cursor position to the bottom of the screen Ctrl+Shift+PgUp Selects from the cursor position to the top of the screen Ctrl+Shift+Tab Moves to the previous page
Shift+Alt+arrow Selects column-oriented blocks Click+Alt+mousemove Selects column-oriented blocks Ctrl+O+C Ctrl+O+K Turns on column blocking Turns off column blocking
Alt+Backspace
Edit|Undo
Alt+Shift+Backspace Alt+Shift+Left Arrow Alt+Shift+Right Arrow
Edit|Redo Selects the column to the left of the cursor Selects the column to the right of the cursor
Alt+Shift+Up Arrow Moves the cursor up one line and selects the column from the left of the starting cursor position Alt+Shift+Down Arrow Moves the cursor down one line and selects the column from the left of the starting cursor position
Alt+Shift+Page Up Moves the cursor up one screen and selects the column from the left of the starting cursor position Alt+Shift+Page Down Moves the cursor down one line and selects the column from the right of the starting cursor position Alt+Shift+End Selects the column from the cursor position to the end of the current line Alt+Shift+Home Selects the column from the cursor position to the start of the current line
Ctrl+Alt+Shift+Left Arrow cursor
Selects the column to the left of the
Ctrl+Alt+Shift+Right Arrow cursor
Selects the column to the right of the
Ctrl+Alt+Shift+Home Selects the column from the cursor position to the start of the current file Ctrl+Alt+Shift+End Selects the column from the cursor position to the end of the current file Ctrl+Alt+Shift+Page Up Selects the column from the cursor position to the bottom of the screen Ctrl+Alt+Shift+Page Down Selects the column from the cursor position to the top of the screen