Force C++Builder to close a database session even if aborted -
Form 1 connects to a database and maintains connections in a published property Form1-> Dbession.
In Project Source I want to make sure that this session has closed, even if the program exception (in a library) is thrown.
In my code
USEFORM ("fForm1.cpp", form1);
When writing this code in WinMain
try {application-> gt; Initialize (); Applications-> CreateForm (__class (TForm1), and Form 1); Application & gt; Run (); } __finally {form 1-> Dbsation-> Close (); }
The compiler does not compile because it does not know TForm1. I can not include the header file because I also use the USEFORM and redistribute error.
You do not need to add that. Finally, after WinMain () is blocked inside WinMain (), all active TForm objects are automatically free. Just close your mainframe to DBSition within your destructor.
Comments
Post a Comment