Trapping errors in TClientDataSet.CommandText

Posted by Rob McDonell on Stack Overflow See other posts from Stack Overflow or by Rob McDonell
Published on 2010-05-13T02:52:45Z Indexed on 2010/05/13 3:04 UTC
Read the original article Hit count: 419

I have a TClientDataSet connected to a TDataSetProvider, which in turn is connected to a TAdsTable. I set the SQL command and then open the ClientDataset something like this:

try
  CDS.CommandText := 'SELECT * FROM tablename WHERE fieldname = 1';
  CDS.Open
except
  // trap exception here - this never gets executed!
end;

If the SQL statement in CommandText fails, however (syntax error or whatever) I get an exception within the Advantage code, but it never gets caught in my own exception handling code.

Is there any way for me to trap this error and report it nicely to the user. Alternatively is there a way to verify the syntax of an SQL query before executing it?

I'm using Delphi Pro 2009, and Advantage Local Server 9.

© Stack Overflow or respective owner

Related posts about delphi

Related posts about tclientdataset