I have a program that needs data from a SQL-Server, it can't work without (well, it can but has totally no use).
There are 2 autocreate forms, DMOD and Main, in that order.
This is the code in the OnCreate of DMOD:
if not fileexists(UdlFile) then
begin
ITRCreateFile(UdlFile);
ShellExecute(Application.Handle,'open',UdlFile,nil,nil,SW_SHOW);
try
cnConnect.Close;
if gServerPort <> '' then
cnConnect.connectionString:= 'Provider=SQLOLEDB.1;Password=*;Persist Security Info=True;User ID=itreflex;Initial Catalog=ExquisStudio;Data Source=' + gServerName + '\' + gServerPort + ';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=' + gServerName + ';Use Encryption for Data=False;Tag with column collation when possible=False'
else
cnConnect.connectionString:= 'Provider=SQLOLEDB.1;Password=*;Persist Security Info=True;User ID=itreflex;Initial Catalog=ExquisStudio;Data Source=' + gServerName + ';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=' + gServerName + ';Use Encryption for Data=False;Tag with column collation when possible=False';
cnConnect.Open();
except
Showmessage('Problems with dataconnection - error SQL data');
screen.Cursor := crDefault;
Application.terminate;
end;
end
else
begin
try
cnConnect.Close;
if gServerPort <> '' then
cnConnect.connectionString:= 'Provider=SQLOLEDB.1;Password=*;Persist Security Info=True;User ID=itreflex;Initial Catalog=ExquisStudio;Data Source=' + gServerName + '\' + gServerPort + ';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=' + gServerName + ';Use Encryption for Data=False;Tag with column collation when possible=False'
else
cnConnect.connectionString:= 'Provider=SQLOLEDB.1;Password=*;Persist Security Info=True;User ID=itreflex;Initial Catalog=ExquisStudio;Data Source=' + gServerName + ';Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=' + gServerName + ';Use Encryption for Data=False;Tag with column collation when possible=False';
cnConnect.Open();
except
Showmessage('Problems with dataconnection - error SQL data');
screen.Cursor := crDefault;
Application.terminate;
end;
end;
The problem is, the program closes, there is nothing left that is visible, but the process keeps running, mostly at 95% or higher CPU-usage. That's not really good....
I did some digging and found Thread not terminated while application is terminated under Delphi
I added ExitProcess(0);
after both Application.terminate;
and now the process closes as should be. I used 0 because the parameter is required, I have no idea what it really should be.
My question is: Is it OK to do it this way? It does what I want but I have the feeling I'm overlooking something.