Page 1 of 1

Runtime error 216 while destroying connection

Posted: 28.02.2007, 12:28
by law
Running a query in TZQuery without Application.Run in the project source cause Runtime error 216. See the uploaded demo project.

Posted: 28.02.2007, 14:26
by mdaems
Well,

The way you wrote this doesn't look very nice, I think. I'm not a real experienced Delphi writer, but I think you should call Application.Run to be able to process exceptions thrown by the application. (That seems to be the place where the Runtime error is Thrown.) Too prove this I added a procedure to TDM that raises an exception and called that instead of DM.q.Open; That also causes a runtime exception.

My advice : use application.Run and do a Application.terminate when opening the connection fails in your form or the data module.

Mark

Posted: 28.02.2007, 21:48
by law
Yes, it doesn't look very nice. I wrote it to log in users to the application. This method worked perfectly in D4 with BDE. I rewrote this part of my code, placed the log in code to MainForm.FormShow, but the form shows then closes if the user click cancel on log in form. It doesn't look very nice too.
In the sample program, access violation caused by TZConnection.Disconnect in line FConnection.Close. FConnection is not nil, so I can't understand why there's an av.
Any other programs work fine with this method in project source.

Anyway, I solved my problem, thanks for your advice.