I had the opportunity to try this using the compiler :) I have to install it one day at home.
While I still find your WITH usage unusual, it seems to work fine.
I saw the error you get in several cases:
- Trying to run multiple requests against the connection at once (due to thread or timer + processMessages)
- With TADOStoredProc when an invalid procedure name
- Sometimes, if ADO cannot parse the query, it cannot verify this without your DB schema.
Note that in SQL Server there is no need to explicitly determine the type of parameter. They are automatically assigned by the OnChanged event attached to the TStringList SQL object.
As a result, it is best to either set the SQL.Text property (like you) or use .Add ('SELECT ...'), use the SQL.BeginUpdate / SQL.EndUpdate pair.
Original answer:
with AQ_Query do begin try AQ_Query := TADOQuery.Create(nil); ConnectionString := strConnectionString;
While this works, it seems a little strange to refer to an object before you create it.
AQ_Query must be instantiated before the with statement:
AQ_Query := TADOQuery.Create(nil); with AQ_Query do begin try ConnectionString := strConnectionString;
It's better not to use WITH yet - it asks for trouble.
Also note that the creation of the object must be before trying. As written, you will have a compiler warning. Do not ignore them - they help you write code better.
source share