Jump to content

Try/Except eDataBaseError in Unigui


luizdspinola

Recommended Posts

Hello everybody.

I'm having a hard time developing a database insert.

I have a custom auto inc field that is managed by the application, I use try/except combined with EDatabaseError to handle error if duplicate insertion attempt happens but execution interrupts without going through except

See the code:

 

procedure insere_dados(NUMERO: INTEGER):

begin

  try

     TABELA.FieldByName('INC').AsString:= NUMERO;                   //CHAVE PRIMARIA

      TABELA.FieldByName('DATA').AsString:= DateToStr(now);
      TABELA.FieldByName('USUARIO').AsString:= ID_Usuario;
      TABELA.Post;
      TABELA.ApplyUpdates;                                                          //ATUALIZA BASE DE DADOS
      MessageDlg('Informações inseridas com sucesso.', mtInformation, [mbOK]);
  except
    on eDataBaseError  do                            //or EFDDBEngineException
    begin
      TABELA.Cancel;
      TABELA.CancelUpdates;         //CANCELA ATUALIZACAO
      NUMERO:= NUMERO+1;         //INCREMENTA NUMERO
      insere(NUMERO);                    //CHAMA A PROC NOVAMENTE
    end;        

end;

Link to comment
Share on other sites

  • 1 month later...
×
×
  • Create New...