procedure TForm1.FormShow(Sender: TObject); begin Edit1.Enabled:=false; Edit2.Enabled:=false; Edit3.Enabled:=false; Edit4.Enabled:=false; Edit5.Enabled:=false; Edit1.Clear; Edit2.Clear; Edit3.Clear; Edit4.Clear; Edit5.Clear; end;
procedure TForm1.Button1Click(Sender: TObject); begin if Button1.Caption='Tambah' then begin Edit1.Enabled:=true; //mengaktifkan edit1 Edit1.SetFocus; //memfokuskan edit1 Button1.Caption:='Batal'; //mengganti caption button1 menjadi batal end else begin Edit1.Enabled:=false; // Edit2.Enabled:=false; // Edit3.Enabled:=false; // menonaktifkan semua komponen edit Edit4.Enabled:=false; // Edit5.Enabled:=false; // Edit1.Clear; // Edit2.Clear; // Edit3.Clear; // membersihkan semua komponen edit Edit4.Clear; // Edit5.Clear; // Button1.Caption:='Tambah'; //merubah caption button1 menjadi tambah end; end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then //bila tombol enter ditekan begin if Edit1.Text='' then //bila field edit kosong begin Application.MessageBox('maaf data harus diisi','Keslahan',MB_OK or MB_ICONWARNING); end else begin Edit2.Enabled:=true; //mengaktifkan edit2 Edit2.SetFocus; //mefocuskan edit2 end; end; end;
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Button1: TButton; procedure FormShow(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure Edit2KeyPress(Sender: TObject; var Key: Char); procedure Edit3KeyPress(Sender: TObject; var Key: Char); procedure Edit4KeyPress(Sender: TObject; var Key: Char); procedure Edit5KeyPress(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormShow(Sender: TObject); begin Edit1.Enabled:=false; Edit2.Enabled:=false; Edit3.Enabled:=false; Edit4.Enabled:=false; Edit5.Enabled:=false; Edit1.Clear; Edit2.Clear; Edit3.Clear; Edit4.Clear; Edit5.Clear; end; procedure TForm1.Button1Click(Sender: TObject); begin if Button1.Caption='Tambah' then begin Edit1.Enabled:=true; //mengaktifkan edit1 Edit1.SetFocus; //memfokuskan edit1 Button1.Caption:='Batal'; //mengganti caption button1 menjadi batal end else begin Edit1.Enabled:=false; // Edit2.Enabled:=false; // Edit3.Enabled:=false; // menonaktifkan semua komponen edit Edit4.Enabled:=false; // Edit5.Enabled:=false; // Edit1.Clear; // Edit2.Clear; // Edit3.Clear; // membersihkan semua komponen edit Edit4.Clear; // Edit5.Clear; // Button1.Caption:='Tambah'; //merubah caption button1 menjadi tambah end; end; procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then //bila tombol enter ditekan begin if Edit1.Text='' then //bila field edit kosong begin Application.MessageBox('maaf data harus diisi','Keslahan',MB_OK or MB_ICONWARNING); end else begin Edit2.Enabled:=true; //mengaktifkan edit Edit2.SetFocus; //mefocuskan edit end; end; end; procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then //bila tombol enter ditekan begin if Edit2.Text='' then //bila field edit kosong begin Application.MessageBox('maaf data harus diisi','Keslahan',MB_OK or MB_ICONWARNING); end else begin Edit3.Enabled:=true; //mengaktifkan edit Edit3.SetFocus; //mefocuskan edit end; end; end; procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then //bila tombol enter ditekan begin if Edit3.Text='' then //bila field edit kosong begin Application.MessageBox('maaf data harus diisi','Keslahan',MB_OK or MB_ICONWARNING); end else begin Edit4.Enabled:=true; //mengaktifkan edit Edit4.SetFocus; //mefocuskan edit end; end; end; procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then //bila tombol enter ditekan begin if Edit4.Text='' then //bila field edit kosong begin Application.MessageBox('maaf data harus diisi','Keslahan',MB_OK or MB_ICONWARNING); end else begin Edit5.Enabled:=true; //mengaktifkan edit Edit5.SetFocus; //mefocuskan edit end; end; end; procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then //bila tombol enter ditekan begin if Edit5.Text='' then //bila field edit kosong begin Application.MessageBox('maaf data harus diisi','Keslahan',MB_OK or MB_ICONWARNING); end else begin Button1.SetFocus; end; end; end; end.
procedure kondisiAwal; var a:Integer; begin with Form1 do begin for a :=0 to ComponentCount-1 do begin if Components[a] is TEdit then TEdit(Components[a]).Clear; //membersihkan semua komponen TEdit if Components[a] is TEdit then TEdit(Components[a]).Enabled := False; //menonaktifkan semua komponen TEdit Button1.Caption:='Tambah'; Button1.SetFocus; end; end; end;
procedure TForm1.FormShow(Sender: TObject); begin kondisiAwal; end;
procedure TForm1.Button1Click(Sender: TObject); begin if Button1.Caption='Tambah' then begin Edit1.Enabled:=true; Edit1.SetFocus; Button1.Caption:='Batal'; end else begin kondisiAwal; //bila button1 captionnya batal , maka kondisiAwal dipanggil end; end;
procedure cekEdit(sender,fokus:TObject);//sender adalah Tedit awal , dan fokus Tedit tujuan begin with(sender as TEdit) do begin if Text='' then //bila sender kosong begin Application.MessageBox('Maaf data harus di isi','Kesalahan',MB_OK or MB_ICONWARNING); end else begin with(fokus as TEdit) do begin Enabled:=true; SetFocus; end; end; end; end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin cekEdit(Sender,Edit2); end; end;
procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin if Edit5.Text='' then begin Application.MessageBox('Maaf data harus di isi','Kesalahan',MB_OK or MB_ICONWARNING); end else begin Button1.SetFocus; end; end; end;
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Button1: TButton; procedure FormShow(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure Edit2KeyPress(Sender: TObject; var Key: Char); procedure Edit3KeyPress(Sender: TObject; var Key: Char); procedure Edit4KeyPress(Sender: TObject; var Key: Char); procedure Edit5KeyPress(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure kondisiAwal; var a:Integer; begin with Form1 do begin for a :=0 to ComponentCount-1 do begin if Components[a] is TEdit then TEdit(Components[a]).Clear; //membersihkan semua komponen TEdit if Components[a] is TEdit then TEdit(Components[a]).Enabled := False; //menonaktifkan semua komponen TEdit Button1.Caption:='Tambah'; Button1.SetFocus; end; end; end; procedure cekEdit(sender,fokus:TObject);//sender adalah Tedit awal , dan fokus Tedit tujuan begin with(sender as TEdit) do begin if Text='' then //bila sender kosong begin Application.MessageBox('Maaf data harus di isi','Kesalahan',MB_OK or MB_ICONWARNING); end else begin with(fokus as TEdit) do begin Enabled:=true; SetFocus; end; end; end; end; procedure TForm1.FormShow(Sender: TObject); begin kondisiAwal; end; procedure TForm1.Button1Click(Sender: TObject); begin if Button1.Caption='Tambah' then begin Edit1.Enabled:=true; Edit1.SetFocus; Button1.Caption:='Batal'; end else begin kondisiAwal; //bila button1 captionnya batal , maka kondisiAwal dipanggil end; end; procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin cekEdit(Sender,Edit2); end; end; procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin cekEdit(Sender,Edit3); end; end; procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin cekEdit(Sender,Edit4); end; end; procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin cekEdit(Sender,Edit5); end; end; procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char); begin if Key=#13 then begin if Edit5.Text='' then begin Application.MessageBox('Maaf data harus di isi','Kesalahan',MB_OK or MB_ICONWARNING); end else begin Button1.SetFocus; end; end; end; end.
2 komentar:
bener ini gan... bener2 manfaat...
nice share mas bro........
Posting Komentar