Intercept/change DB error message

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
polsol
Posts: 71
Joined: Sun 20 May 2007 13:29
Contact:

Intercept/change DB error message

Post by polsol » Tue 16 Apr 2019 15:01

Please consider a grid with 2 columns (simplified). The first column is a 'lookup' column ("Name") while the second is a required field (ID Number).
Column A is used to select a 'Name' from a DB Lookup list and fill the associated ID Number into the second Column: "ID Number". Note that the actual value for "Name" does not have an underlying Field component in this table - column A just exists to get the ID Number and enter it in the table.

If one tries to post a record without selecting the 'Name' (and hence adding the ID number into the ID number field), one gets the error message "Field "ID Number" must have a value".
This could, of course, be confusing to the end user as the field they're entering is "Name" - not "ID Number" (especially if the ID number is not visible in the grid) ....
How can one intercept the database error mechanism to change the error message to "Field "Name" must have a value" to avoid confusion when the ID Number Field is null?

Stellar
Devart Team
Posts: 250
Joined: Tue 03 Oct 2017 11:00

Re: Intercept/change DB error message

Post by Stellar » Tue 23 Apr 2019 10:39

You can try processing the BeforePost event for TDataSet and check the value of the field you're interested in. If the value is invalid, you can generate a custom error for the user. For example:

Code: Select all

procedure TForm1.UniQuery1BeforePost(DataSet: TDataSet);
begin
  if DataSet.FieldByName('Field_Name').IsNull then
    DatabaseError('Error message');
end;

polsol
Posts: 71
Joined: Sun 20 May 2007 13:29
Contact:

Re: Intercept/change DB error message

Post by polsol » Tue 23 Apr 2019 11:12

Thanks Stellar,
That's what I have now started doing and it works fine.
I was thinking there might be a simpler way.

Stellar
Devart Team
Posts: 250
Joined: Tue 03 Oct 2017 11:00

Re: Intercept/change DB error message

Post by Stellar » Wed 24 Apr 2019 15:06

Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.

Post Reply