In the previous tutorial, an error occur when you try to delete a record in ‘employee’ table. It is because of the ‘salary’ table refers to the record. An error message will appear. To avoid this, we’re going to create an exception handle.
Let’s see what kind of error will happen if we try to delete a record in ‘employee’ table. Run the program from Delphi IDE (not the executable file). You’ll see the error message below :
From the message, the exception that raised is EDBEngineError. Let’s see our code for OnClick event of Delete button. You have to add an exception handle code using TRY…..EXCEPT :
procedure TForm1.DeleteClick(Sender: TObject);
begin
try
Table1.Delete;
except
on EDBEngineError do
begin
MessageDlg('You can not delete this record because another table is currently using the data',
mtError,[mbOK],0)
end;
end;
end;
Then if you run the program and try to delete a record in ‘employee’ table that a record in ‘salary’ table refers to it, you’ll get a message like picture below :
Thanks for sharing about Delphi . its a very good thing about share knowledge. outsourcing services on Delphi
ReplyDeletesupplier of 3D printing, rapid prototyping, rapid manufacturing, plastic fabrication, tooling, CNC and injection molding services.
ReplyDelete