Problem with Delphi 10.1 + Firedac (Autopost)

Asked

Viewed 653 times

1

I have a Procedure simple to save in database. In it I also made a control cases the mandatory fields are not filled in making the system avoid recording wrong data or missing information.

However by mystery or magic the record is saved in the database. I do not know if you have any configuration of _FireDAC_ in the table and or in the connection component. If anyone has been there and can help me, thank you.

Code

procedure TfrmManutencaoUsuarios.btnSalvaUnidadeClick(Sender: TObject);
begin
  // verifica os items
  if dbeUsuarioUnidade.Text = '' then
  begin
    Application.MessageBox('Campo Nome do Usuário é Obrigatório!','Aviso', 
        MB_OK+MB_ICONEXCLAMATION);
    dbeUsuarioUnidade.SetFocus;
    exit;
  end;

  if dbcUsuarioUnidade.Text = '' then
  begin
    Application.MessageBox('Nome da Unidade é Obrigatório!','Aviso', 
        MB_OK+MB_ICONEXCLAMATION);
    dbcUsuarioUnidade.SetFocus;
    exit;
  end;
  // Verifica se a Unidade já está acessível para o Usuário
  if DataModuleGeral.tbUsuariosUnidades.Locate('USUARIO_NOME;UNIDADE_NOME',
     VarArrayOf([dbeUsuarioUnidade.Text, dbcUsuarioUnidade.Text]),[]) then
  begin
    Application.MessageBox('Esta Unidade já está Acessível para este 
       usuário!','Aviso', MB_OK+MB_ICONEXCLAMATION);
    dbcUsuarioUnidade.SetFocus;
    exit;
  end else
  begin
    // Salva na Tabela
    DataModuleGeral.tbUsuariosUnidades.Post;
  end;
end;
  • 1

    Do you use Fdquery or Fdtable? The fields in the database table have a Default Value? And finally, which database are you using?

  • Usos Fdtable, does not have a Default Value in the Field, the bank is Firebird

  • 1

    A little difficult to help when we don’t know all the source code. But there are some possibilities: 1. Some other point of the source is giving post. There doesn’t necessarily have to be the Post statement, sometimes the fact that you navigate between the table records already generates a post. Could this be happening? Also suggest instead of seeing if dbedit is filled in, check directly in fdtable, example: if tbUsuariosUnidades.Fieldbyname('name'). Asstring = '' then...

  • That’s the whole source of what you record in the bank. There is no other way, you fill out the edit and press the button the system checks whether to edit this blank if yes it exits if not it do the other checks, but the point in question is not the edit but the end of the code that even finding the record in the database it records repeated...

1 answer

0


What if you so don’t solve it? I did it in mine and it works here for me.

To Enable:

DataModuleGeral.SeuBanco.TxOptions.AutoCommit := True;

To Disable

DataModuleGeral.SeuBanco.TxOptions.AutoCommit := False; 
  • 1

    Datamodulegeneral.SeuBanco.Txoptions.Autocommit := True;To Enable Datamodulegeneral.SeuBanco.Txoptions.Autocommit := False; To Disable

Browser other questions tagged

You are not signed in. Login or sign up in order to post.