Sunteți pe pagina 1din 14

Membuat Database Tools ñ Database Desktop File ñ New ñ Table

Tools ñ Database Desktop File ñ New ñ Table Klik Ok Buat Struktur Database seperti tampilan

Klik Ok Buat Struktur Database seperti tampilan di bawah ini :

| Tutorial Borland Delphi

seperti tampilan di bawah ini : | Tutorial Borland Delphi Simpan dengan nama Mhs.db, gunakan [Space]

Simpan dengan nama Mhs.db, gunakan [Space] untuk memilih Type dan memberikan tanda * pada Key

 

|

Tutorial Borland Delphi

Desain Form seperti di bawah ini :

 
 

Komponen

Properties

Nilai

Form1

Name

FrmMhs

Table1

Name

TMhs

 

TableName

Mhs.db

 

Active

True

DataSource

Name

DsMhs

 

Dataset

TMhs

DBGrid1

Datasource

DsMhs

Catatan : Klik kanan komponen TMhs ñ Field Editor ñ Klik kanan Field Editor ñ Add all Fields

Edit1

Name

EdNim

 

Enabled

False

 

CharChase

ecUpperCase

Edit2

Name

EdNmmhs

 

Enabled

False

Edit3

Name

EdAlMhs

 

Enabled

False

Edit4

Name

EdTplhr

 

Enabled

False

DTPicker1

Name

DtpTglhr

 

|

Tutorial Borland Delphi

 

Enabled

False

GroupBox

Name

GbJekel

 

Enabled

False

RadioButton1

Name

RbPria

RadioButton2

Name

RbWanita

Edit5

Name

EdJrs

 

Enabled

False

Edit6

Name

EdTahun

 

Enabled

False

Button1

Name

BtTambah

 

Caption

&Tambah

Button2

Name

BtUbah

 

Caption

&Ubah

Button3

Name

BtHapus

 

Caption

&Hapus

Button4

Name

BtSimpan

 

Caption

&Simpan

 

Enabled

False

Button5

Name

BtKeluar

 

Caption

&Keluar

Button6

Name

BtAwal

 

Caption

9

 

Font (Name)

Webdings

Button7

Name

BtSebelum

 

Caption

7

 

Font(Name)

Webdings

Button8

Name

BtSetelah

 

Caption

8

 

Font(Name)

Webdings

Button9

Name

:

 

Caption

BtAkhir

 

Font(Name)

Webdings

Button10

Name

BtTipsMhs

Listing Program | unit UMhs;

interface

uses

| Tutorial Borland Delphi

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids, StdCtrls, ComCtrls, Db, DBTables;

type TFrmMhs = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; EdNim: TEdit; EdNmmhs: TEdit; EdAlMhs: TEdit; EdTplhr: TEdit; DtpTglhr: TDateTimePicker; RbPria: TRadioButton; RbWanita: TRadioButton; BtTambah: TButton; BtUbah: TButton; BtHapus: TButton; BtSimpan: TButton; BtKeluar: TButton; GbNavigasi: TGroupBox; BtAwal: TButton; BtSebelum: TButton; BtSetelah: TButton; BtAkhir: TButton; GbJekel: TGroupBox; TMhs: TTable; DsMhs: TDataSource; BtTips: TButton; TMhsNim: TStringField; TMhsNmmhs: TStringField; TMhsAlMhs: TStringField; TMhsTplhr: TStringField; TMhsTglhr: TDateField; TMhsJekel: TStringField; TMhsJrs: TStringField; EdJrs: TEdit; Label7: TLabel; DBGrid1: TDBGrid;

Label8: TLabel; EdTahun: TEdit; TMhsTahun: TStringField; procedure BtTipsClick(Sender: TObject); procedure BtKeluarClick(Sender: TObject); procedure BtAwalClick(Sender: TObject); procedure BtAkhirClick(Sender: TObject);

procedure BtSebelumClick(Sender: TObject); procedure BtSetelahClick(Sender: TObject); procedure BtTambahClick(Sender: TObject); procedure BtUbahClick(Sender: TObject); procedure BtHapusClick(Sender: TObject); procedure BtSimpanClick(Sender: TObject); procedure EdNimChange(Sender: TObject); procedure FormCreate(Sender: TObject); private

{ Private declarations } public

{ Public declarations }

Procedure Aturtext(A:Boolean);

Procedure KondisiAwal; Procedure DataKosong; Procedure DataMhs; Procedure Bersih; end;

var FrmMhs: TFrmMhs;

implementation

uses UTipsMhs; Procedure TFrmMhs.Aturtext(A:Boolean); Begin EdNim.Enabled := A; EdNmmhs.Enabled :=A; EdAlmhs.Enabled :=A; EdTplhr.Enabled :=A; DtpTglhr.Enabled :=A; GbJekel.Enabled :=A; EdJrs.Enabled :=A; Edtahun.Enabled :=A;

| Tutorial Borland Delphi

End;

Procedure TFrmMhs.KondisiAwal; Begin BtAwal.Click; BtTambah.Caption :='&Tambah'; BtUbah.Caption :='&Ubah'; BtHapus.Caption :='&Hapus'; BtSimpan.Caption :='&Simpan'; BtTambah.Enabled :=True; BtUbah.Enabled :=True; BtHapus.Enabled :=True; BtSimpan.Enabled :=False; Aturtext(False); GbNavigasi.enabled:=True; End;

Procedure TFrmMhs.DataKosong; Begin Bersih; Aturtext(False); GbNavigasi.enabled:=False; BtUbah.Enabled:=False; BtHapus.Enabled:=False; BtSimpan.Enabled:=False; End;

Procedure TFrmMhs.DataMhs; Begin If TMhs.RecordCount <> 0 Then Begin EdNim.Text :=TMhsNim.Value; EdNmmhs.Text :=TMhsNmmhs.Value; EdAlmhs.Text :=TMhsAlMhs.Value; EdTplhr.Text :=TMhsTplhr.Value; DtpTglhr.Date :=TMhsTglhr.Value; If TMhsJekel.Value ='Pria' Then RbPria.Checked:=True Else RbWanita.Checked:=True; EdJrs.Text := TMhsJrs.Value; Edtahun.Text := TMhsTahun.Value;

| Tutorial Borland Delphi

end; End; Procedure TFrmMhs.Bersih; Begin EdNim.Text :=''; EdNmmhs.Text :=''; EdAlMhs.Text :=''; EdTplhr.Text :=''; DtpTglhr.Date :=Now; RbPria.Checked:=False; RbWanita.Checked:=False; EdJrs.Text :=''; EdTahun.Text :=''; End;

{$R *.DFM}

procedure TFrmMhs.BtKeluarClick(Sender: TObject); begin TMhs.Close; Close; end;

procedure TFrmMhs.BtAwalClick(Sender: TObject); begin TMhs.First; DataMhs; end;

procedure TFrmMhs.BtAkhirClick(Sender: TObject); begin TMhs.Last; DataMhs; end;

procedure TFrmMhs.BtSebelumClick(Sender: TObject); begin

TMhs.MoveBy(-1);

DataMhs;

end;

| Tutorial Borland Delphi

procedure TFrmMhs.BtSetelahClick(Sender: TObject); begin

TMhs.MoveBy(1);

DataMhs;

end;

procedure TFrmMhs.BtTambahClick(Sender: TObject); begin If BtTambah.Caption ='&Tambah' Then Begin BtTambah.Caption :='&Batal'; BtUbah.Enabled :=False; BtHapus.Enabled :=False; BtSimpan.Enabled :=True; Aturtext(True); GbNavigasi.Enabled :=False; Bersih; EdNim.SetFocus; End Else KondisiAwal; end;

procedure TFrmMhs.BtUbahClick(Sender: TObject); begin If BtUbah.Caption ='&Ubah' Then Begin BtUbah.Caption :='&Batal'; BtTambah.Enabled :=False; BtHapus.Enabled :=False; BtSimpan.Enabled :=True; Aturtext(True); EdNim.SetFocus; End Else KondisiAwal; end;

procedure TFrmMhs.BtHapusClick(Sender: TObject); begin If BtHapus.Caption ='&Hapus' Then Begin

| Tutorial Borland Delphi

BtHapus.Caption :='&Batal'; BtSimpan.Caption :='&Hapus'; BtUbah.Enabled :=False; BtTambah.Enabled :=False; BtSimpan.Enabled :=True; Aturtext(True); EdNim.SetFocus; End Else KondisiAwal; end;

procedure TFrmMhs.BtSimpanClick(Sender: TObject); begin If BtTambah.Caption ='&Batal' Then Begin If Not Tmhs.FindKey([EdNim.text]) Then Begin TMhs.Append; TMhsNim.Value:=EdNim.Text; TMhsNmmhs.Value:=EdNmmhs.Text; TMhsAlMhs.Value:=EdAlMhs.Text; TMhsTplhr.Value:=EdTplhr.Text; TMhsTglhr.Value:=DtpTglhr.Date; If RbPria.Checked =True Then TMhsJekel.Value :='Pria' Else TmhsJekel.value:='Wanita'; TMhsJrs.Value:=EdJrs.Text; TMhsTahun.Value:=EdTahun.Text; TMhs.Post; BtTambah.click; end; end;

If BtUbah.Caption ='&Batal' Then Begin If Tmhs.FindKey([EdNim.text]) Then Begin TMhs.Edit; TMhsNmmhs.Value:=EdNmmhs.Text; TMhsAlMhs.Value:=EdAlMhs.Text;

| Tutorial Borland Delphi

TMhsTplhr.Value:=EdTplhr.Text; TMhsTglhr.Value:=DtpTglhr.Date; If RbPria.Checked =True Then TMhsJekel.Value :='Pria' Else TmhsJekel.value:='Wanita'; TMhsJrs.Value:=EdJrs.Text; TMhsTahun.Value:=EdTahun.Text; TMhs.Post; BtUbah.Click; end; end;

If BtHapus.Caption ='&Batal' Then Begin If Tmhs.FindKey([EdNim.text]) Then Begin Tmhs.Delete; BtHapus.Click; end; end; end;

| Tutorial Borland Delphi

procedure TFrmMhs.EdNimChange(Sender: TObject); begin If (BtUbah.Caption ='&Batal') or (BtHapus.Caption ='&Batal') Then Begin If Tmhs.FindKey ([EdNim.text]) Then DataMhs; end; end;

procedure TFrmMhs.FormCreate(Sender: TObject); begin TMhs.Open; DataMhs;

DBGrid1.Refresh;

end; procedure TFrmMhs.BtTipsClick(Sender: TObject); begin FrmTipsMhs.Show;

FrmTipsMhs.LblKondisi.caption:='1';

 

|

Tutorial Borland Delphi

end; end. Form Cari Data Mahasiswa

 
 

Komponen

Properties

Nilai

Form1

Name

FrmTipsMhs

Query1

Name

QMhs

 

SQL

SELECT * FROM Mhs

Datasource1

Name

DsMhs

 

Dataset

QMhs

ComboBox1

Name

CmbField

 

Items

Nomor Induk Mahasiswa Nama Mahasiswa

Edit1

Name

EdData

DBGrid1

Name

DBGrid1

 

Datasource

DsMhs

Button1

Name

BtCari

 

Caption

&Cari

Button2

Name

BtKeluar

 

Caption

&Keluar

Label3

Name

LblKondisi

 

Visible

False

Listing Program |

unit UTipsMhs;

interface

| Tutorial Borland Delphi

uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids, DBTables, Db;

type TFrmTipsMhs = class(TForm) CboField: TComboBox; EdData: TEdit; BtCari: TButton; BtKeluar: TButton; Label1: TLabel; Label2: TLabel; DsMhs: TDataSource; Qmhs: TQuery; LblKondisi: TLabel; DBGrid1: TDBGrid; QmhsNim: TStringField; QmhsNmmhs: TStringField; QmhsAlMhs: TStringField; QmhsTplhr: TStringField; QmhsTglhr: TDateField; QmhsJekel: TStringField; QmhsJrs: TStringField; QmhsTahun: TStringField; procedure EdDataChange(Sender: TObject); procedure FormCreate(Sender: TObject); procedure EdDataKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

procedure DBGrid1KeyPress(Sender: TObject; var Key: Char); procedure BtKeluarClick(Sender: TObject); procedure BtCariClick(Sender: TObject); procedure CboFieldClick(Sender: TObject); procedure EdDataKeyPress(Sender: TObject; var Key: Char); private

{ Private declarations } public

{ Public declarations } end;

var FrmTipsMhs: TFrmTipsMhs;

implementation

uses UMhs;

{$R *.DFM}

| Tutorial Borland Delphi

procedure TFrmTipsMhs.EdDataChange(Sender: TObject); begin If CboField.Text ='Nomor Induk Mahasiswa' Then Begin QMhs.Close; QMhs.SQL.Clear; QMhs.SQL.Add('Select * From Mhs'); QMhs.SQL.Add('WHERE UPPER(Nim) Like '''+UpperCase(EDData.Text)+'%'''); QMhs.SQL.Add ('Order By Nim'); Qmhs.Open; End;

If CboField.Text ='Nama Mahasiswa' Then Begin QMhs.Close; QMhs.SQL.Clear; QMhs.SQL.Add('Select * From Mhs'); QMhs.SQL.Add('WHERE UPPER(Nmmhs) Like ''%'+UpperCase(EDData.Text)+'%'''); QMhs.SQL.Add ('Order By Nim'); Qmhs.Open; end; end;

procedure TFrmTipsMhs.FormCreate(Sender: TObject); begin QMhs.Close; QMhs.SQL.Clear; QMhs.SQL.Add('Select * From Mhs'); QMhs.SQL.Add ('Order By Nim'); Qmhs.Open; end;

procedure TFrmTipsMhs.EdDataKeyDown(Sender: TObject; var Key: Word;

Shift: TShiftState); begin If Key =VK_Down Then Begin DBGrid1.SetFocus ; DBGrid1.SelectedIndex :=0; End; end;

//end;

| Tutorial Borland Delphi

procedure TFrmTipsMhs.DBGrid1KeyPress(Sender: TObject; var Key: Char); begin If Key = Chr(13) Then Begin BtCari.SetFocus; end; end;

procedure TFrmTipsMhs.BtKeluarClick(Sender: TObject); begin Close; end;

procedure TFrmTipsMhs.BtCariClick(Sender: TObject); begin If LblKondisi.caption='1' Then FrmMhs.EdNim.Text := QMhs['Nim']; Close; end;

procedure TFrmTipsMhs.CboFieldClick(Sender: TObject); begin EdData.SetFocus; end;

procedure TFrmTipsMhs.EdDataKeyPress(Sender: TObject; var Key: Char); begin If Key =Chr(13) Then

DBGrid1.SetFocus;

end;

end.