unit Unit2; interface implementation end.
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type Tprosedur = class (TObject)//kita membuat object baru dengan nama TProsedur private {private declaration} public procedure cekEdit(sender1,sender2:TObject); //registrasi procedure procedure bersih(namaForm:TObject); {public declaration} end; implementation procedure Tprosedur.cekEdit(sender1,sender2:TObject); //inisialisasi procedure begin with(sender1 as TEdit) do begin if Text='' then begin Application.MessageBox('maaf data tidak boleh kosong','informasi',MB_OK or MB_ICONINFORMATION); end else begin with(sender2 as TEdit) do begin Enabled:=true; SetFocus; end; end; end; end; procedure Tprosedur.bersih(namaForm:TObject); var a:Integer; begin with(namaForm as TForm) 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 end; end; end; end.
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Unit2;//unit2 di tambahkan ke unit1
var Form1: TForm1; kumpulanProsedur:Tprosedur;//kumpulanProsedur merupakan turunan dari Tprosedur yang terdapat pada Unit2
procedure TForm1.FormShow(Sender: TObject); begin kumpulanProsedur.bersih(Self); //procedure bersih yang terdapat pada Unit2 dipanggil end;
procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Enabled:=true;//mengaktifkan edit1 Edit1.SetFocus;//focus berpindah ke edit1 end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then //jika tombol enter di tekan begin kumpulanProsedur.cekEdit(sender,Edit2); //procedure cekEdit yang terdapat pada Unit2 dipanggil //sender merupakan edit asal , dan edit2 merupakan tujuan focus end; end;
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Unit2; 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; kumpulanProsedur:Tprosedur;//kumpulanProsedur merupakan turunan dari Tprosedur yang terdapat pada Unit2 implementation {$R *.dfm} procedure TForm1.FormShow(Sender: TObject); begin kumpulanProsedur.bersih(Self); //procedure bersih yang terdapat pada Unit2 dipanggil end; procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Enabled:=true; Edit1.SetFocus; end; procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then //jika tombol enter di tekan begin kumpulanProsedur.cekEdit(sender,Edit2); //procedure cekEdit yang terdapat pada Unit2 dipanggil //sender merupakan edit asal , dan edit2 merupakan tujuan focus end; end; procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin kumpulanProsedur.cekEdit(sender,Edit3); end; end; procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin kumpulanProsedur.cekEdit(sender,Edit4); end; end; procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin kumpulanProsedur.cekEdit(sender,Edit5); end; end; procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin kumpulanProsedur.cekEdit(sender,Edit1); end; end; end.
0 komentar:
Posting Komentar