Fórum caixa de dialogo sendo executada 2 vezes #380188
28/06/2010
0
bom dia
tenho um problema no delphi
eu n sei oq acontece
mas executar uma acao como verificar no banco se akele registro existe
ele executa uma excessao
e ai ao dar ok na caixa de dialogo
ela executa de novo
ou seja
2 vezes
pq sera?
e olha q a codificacao eé a msm de anteriormente,.....
pq vou salvando as versoes...
valeu
Diego Macario
Curtir tópico
+ 0Posts
28/06/2010
Marco Salles
Gostei + 0
28/06/2010
Diego Macario
exe....executavel
Gostei + 0
28/06/2010
Fábio Cruz
Gostei + 0
28/06/2010
Diego Macario
olha um dos forms ele é herdado
unit ufrmcadcidade;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ufrmcad, StdCtrls, ImgList, ActnList, DB, AppEvnts, jpeg,
ExtCtrls, Grids, DBGrids, ComCtrls, Buttons;
type
Tfrmcadcidade = class(Tfrmcad)
Label4: TLabel;
Edit3: TEdit;
Edit2: TEdit;
Label2: TLabel;
Label1: TLabel;
Label3: TLabel;
ComboBox2: TComboBox;
procedure FormShow(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure DBGrid1DblClick(Sender: TObject);
procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
procedure BTincluirExecute(Sender: TObject);
procedure BTalterarExecute(Sender: TObject);
procedure BTsalvarExecute(Sender: TObject);
procedure DBGrid1TitleClick(Column: TColumn);
procedure BTcancelarExecute(Sender: TObject);
procedure BTdeletarExecute(Sender: TObject);
procedure Limpa(Sender :TObject);
procedure ExisteCidade;
function Valida: Boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmcadcidade: Tfrmcadcidade;
Cidade : String;
Estado : String;
implementation
uses ubiblio, Udm, udm_pesq, DBClient;
{$R *.dfm}
procedure Tfrmcadcidade.FormShow(Sender: TObject);
begin
inherited;
Ds(DataSource1,DM.cdsCidade);
end;
//*****************************************************************************
procedure Tfrmcadcidade.ComboBox1Change(Sender: TObject);
begin
inherited;
with DM do
begin
case ComboBox1.ItemIndex of
0: cdsCidade.IndexFieldNames := 'CHAVE_CIDADE';
1: cdsCidade.IndexFieldNames := 'CIDADE';
2: cdsCidade.IndexFieldNames := 'ESTADO';
end;
end;
end;
//*****************************************************************************
procedure Tfrmcadcidade.Edit1Change(Sender: TObject);
begin
inherited;
if Length(Edit1.Text) > 0 then
begin
with DM.cdsCidade do
begin
case ComboBox1.ItemIndex of
0: if not Locate('CHAVE_CIDADE',Edit1.Text,[]) then
MessageDlg(Edit1.Text+' não encontrado',mtError,[mbOK],0);
1: if not Locate('CIDADE',Edit1.Text,[loPartialKey,loCaseInsensitive]) then
MessageDlg(Edit1.Text+' não encontrado',mtError,[mbOK],0);
2: if not Locate('ESTADO',Edit1.Text,[loPartialKey,loCaseInsensitive]) then
MessageDlg(Edit1.Text+' não encontrado',mtError,[mbOK],0);
end;
end;
end;
end;
//*****************************************************************************
procedure Tfrmcadcidade.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
inherited;
case ComboBox1.ItemIndex of
0:
begin
if not(key in ['0'..'9',#8,#13]) then
begin
MessageDlg('Somente numeros',mtWarning,[mbOK],0);
key := #0;
end;
end;
end;
end;
//*****************************************************************************
procedure Tfrmcadcidade.BTincluirExecute(Sender: TObject);
begin
inherited;
Edit2.Text := 'Novo';
Edit3.SetFocus;
end;
//*****************************************************************************
procedure Tfrmcadcidade.BTalterarExecute(Sender: TObject);
begin
inherited;
Edit3.SetFocus;
Cidade := Edit3.Text;
Estado := ComboBox2.Text;
end;
//*****************************************************************************
procedure Tfrmcadcidade.BTdeletarExecute(Sender: TObject);
begin
inherited;
Limpa(Sender);
end;
//*****************************************************************************
procedure Tfrmcadcidade.BTsalvarExecute(Sender: TObject);
begin
with DM do
begin
if not Valida then
Exit;
if DataSource1.DataSet.State in [DsEdit] then
begin
cdsCidadeCHAVE_CIDADE.AsInteger := StrToInt(Edit2.Text);
end;
cdsCidadeCIDADE.AsString := Edit3.Text;
cdsCidadeESTADO.AsString := ComboBox2.Text;
inherited;
Limpa(Sender);
end;
end;
//*****************************************************************************
procedure Tfrmcadcidade.BTcancelarExecute(Sender: TObject);
begin
inherited;
Limpa(Sender);
end;
//*****************************************************************************
procedure Tfrmcadcidade.DBGrid1DblClick(Sender: TObject);
begin
inherited;
with DM do
begin
Edit2.Text := IntToStr(cdsCidadeCHAVE_CIDADE.AsInteger);
Edit3.Text := cdsCidadeCIDADE.AsString;
ComboBox2.ItemIndex := ComboBox2.Items.IndexOf(cdsCidadeESTADO.AsString);
end;
end;
//*****************************************************************************
procedure Tfrmcadcidade.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
inherited;
PesqDbgrid(DBGrid1,Rect,Column,State);
ZebraGrid(DM.cdsCidade,DBGrid1,Rect,Column,State);
end;
//*****************************************************************************
procedure Tfrmcadcidade.DBGrid1TitleClick(Column: TColumn);
begin
inherited;
OrdenaDbgrid(DM.cdsCidade,Column);
end;
//*****************************************************************************
function Tfrmcadcidade.Valida: Boolean;
begin
Result := True;
if Edit3.Text = '' then
begin
MessageDlg('O campo Cidade deve ser preenchido', mtInformation, [mbOk], 0);
if Edit3.CanFocus then
Edit3.SetFocus;
Result := False;
Exit;
end;
if ComboBox2.Text = '' then
begin
MessageDlg('O campo Estado deve ser preenchido', mtInformation, [mbOk], 0);
if ComboBox2.CanFocus then
ComboBox2.SetFocus;
Result := False;
Exit;
end;
if ((Cidade <> Edit3.Text) and (Estado <> ComboBox2.Text)) then
ExisteCidade;
end;
//*****************************************************************************
procedure Tfrmcadcidade.Limpa(Sender :TObject);
begin
Edit2.Text := '';
Edit3.Text := '';
ComboBox2.ItemIndex := -1;
end;
//*****************************************************************************
procedure Tfrmcadcidade.ExisteCidade;
begin
with dm_pesq.cdsCidade do
begin
Close;
CommandText := 'select * from cidade where cidade = :cidade and estado = :estado';
Params[0].Value := Edit3.Text;
Params[1].Value := ComboBox2.Text;
Open;
if not IsEmpty then
raise Exception.Create('Cidade já cadastrada'+#13+#13
+'Cidade: '+fieldbyname('CIDADE').AsString+#13
+'Estado: '+fieldbyname('ESTADO').AsString);
end;
end;
//*****************************************************************************
Gostei + 0
28/06/2010
Marco Salles
bom dia
tenho um problema no delphi
eu n sei oq acontece
mas executar uma acao como verificar no banco se akele registro existe
ele executa uma excessao
e ai ao dar ok na caixa de dialogo
ela executa de novo
ou seja
2 vezes
pq sera?
e olha q a codificacao eé a msm de anteriormente,.....
pq vou salvando as versoes...
valeu
Gostei + 0
28/06/2010
Diego Macario
bom dia
tenho um problema no delphi
eu n sei oq acontece
mas executar uma acao como verificar no banco se akele registro existe
ele executa uma excessao
e ai ao dar ok na caixa de dialogo
ela executa de novo
ou seja
2 vezes
pq sera?
e olha q a codificacao eé a msm de anteriormente,.....
pq vou salvando as versoes...
valeu
olha la no final..no existe cidade
Gostei + 0
05/07/2010
Diego Macario
somente para criaçao de caixa de dialogos de excessao
qd é messagedlg ou showmessage n da pal...
alguem ja passou por isso?
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)