bagaimana untuk menonaktifkan button pada delphi misalnya ada
button save,edit,delete,cancel . Button" tersebut akan aktif bila
diperlukan...
kalo bisa tolong kasih contoh skrip nya sedikit ...
Thank you..
untuk koding nya sama sperti posting saya sebelumnya .. tolong ya gan ... atau ada skrip salah yg kurang mohon diperbaiki..thx/ atau perlu buat prosedur baru gak????implementation
{$R *.dfm}
procedure TForm1.tampildata;
begin
with dm.blackberry do //dm->data module
begin
sql.Clear;
sql.Add('select * from blackberry');
Active:=false;
Active:=true;
end;
end;
procedure TForm1.bersih;
begin
Edit1.Clear;
Edit2.Clear;
end;
procedure TForm1.BitBtnExitClick(Sender: TObject);
begin
if MessageDlg('Apakah anda yakin menutup form ini?',mtConfirmation,[mbYes,mbNo
],0)=mryes then Form1.Close;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
tampildata;
bersih;
end;
procedure TForm1.BitBtnSaveClick(Sender: TObject);
begin
if Length(Edit1.Text)<>4 then
begin
ShowMessage('Kode Blackberry harus 4 karakter/tidak boleh kosong !!');
Edit1.SetFocus;
exit;
end;
if Length(Edit2.Text)<1 then
begin
ShowMessage('Nama Blackberry Belum Diisi !!');
Edit2.SetFocus;
exit;
end;
if MessageDlg('Data Blackberry ingin disimpan ?',mtInformation,[mbYes,mbNo],0)=mryes then
dm.dbpakarbb.Execute('insert into blackberry values('''+Edit1.Text+''','''
+Edit2.Text+''')');
Dm.blackberry.Requery;
tampildata;
BitBtnSave.Enabled:=True;
Edit1.SetFocus;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
dm.blackberry.SQL.Clear;
dm.blackberry.SQL.Add('select * from blackberry where kd_bb='''+Edit1.Text+'''');
dm.blackberry.Open;;
if not dm.blackberry.Eof then
begin
if MessageDlg('Nama Blackberry sudah ada, ingin diedit ?',mtInformation,[mbYes,mbNo],0)=mryes then
begin
Edit2.Text:=dm.blackberry.FieldValues['nm_bb'];
Edit1.Enabled:=false;
BitBtnEdit.Enabled:=true;
BitBtnDelete.Enabled:=true;
BitBtnSave.Enabled:=false;
BitBtnCancel.Enabled:=true;
edit2.SetFocus;
end
else
begin
tampildata;
exit;
end;
end;
end;
procedure TForm1.BitBtnCancelClick(Sender: TObject);
begin
tampildata;
BitBtnSave.Enabled:=True;
Edit1.SetFocus;
end;
procedure TForm1.BitBtnEditClick(Sender: TObject);
begin
if MessageDlg('Yakin untuk diupdate ??',mtInformation,[mbYes,mbno],0)=mryes then
dm.dbpakarbb.Execute('update blackberry set nm_bb='''+Edit2.Text+''' where kd_bb='''
+Edit1.Text+'''');
dm.blackberry.Requery;
ShowMessage('Data sudah diupdate');
tampildata;
BitBtnSave.Enabled:=true;
bersih;
exit;
end;
procedure TForm1.BitBtnDeleteClick(Sender: TObject);
begin
if MessageDlg('Data Blackberry Ingin dihapus ?',mtInformation,[mbYes,mbNo],0)=mrYes then
dm.dbpakarbb.Execute('delete from blackberry where kd_bb='''+Edit1.Text+'''');
dm.blackberry.Requery;
ShowMessage('Data sudah dihapus');
tampildata;
BitBtnSave.Enabled:=True;
bersih;
exit;
end;
procedure TForm1.BitBtnRefreshClick(Sender: TObject);
var n,urutan,jkarakter:integer;
kbaru:string[4];
begin
dm.blackberry.sql.Clear;
dm.blackberry.sql.add('select * from blackberry order by kd_bb');
dm.blackberry.open;
if dm.blackberry.recordcount=0 then
n:=1
else begin
dm.blackberry.last;
urutan:=strtoint(copy(dm.blackberry.fieldvalues['kd_bb'],2,3));
n:=urutan+1;
end;
jkarakter:=length(trim(inttostr(n)));
case jkarakter of
1:kbaru:='B00'+trim(inttostr(n));
2:kbaru:='B0'+trim(inttostr(n));
3:kbaru:='B'+trim(inttostr(n));
end;
edit1.text:=kbaru;
edit1.selstart:=length(kbaru);
edit2.setfocus;
tampildata;
bitbtnsave.enabled:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.
Tidak ada komentar:
Posting Komentar