Capture Post errors  

Send By: Radikal (Q3 Team)
Web :
Date: 22/01/00

Tip accessed 628 times


It is a question that I have already answered it some that another time, so I will write it in this trick for not answering it more.
When we use DataAware controls such as DBNavigator or DBGrid, and they can add registers it is possible that the user introduces two registers with the same key field, being generated an exception therefore.
How can we capture this exception?, since the Post is made for the corresponding database control (DBGrid, etc)
So... it's very easy, the errors generated making the Post in a table, are centralized in the OnPostError event of the TTable... we will only have to use it.

For example, using a similar code to this:

 procedure TForm1.Table1PostError(DataSet: TDataSet; E: EDatabaseError;
   var Action: TDataAction);
   {Error in the Post}
   ShowMessage('Error al dar de alta un nuevo registro'+#13+

With the parameter Action, we can specify that it is what it is necessary to make with the Post that it generated the error.
In the example, we use daAbort to abort the Post.