I'm developing a component (visual indicator) that for searching the data in the Database and generating the indicator itself uses a Thread. This thread is inside the component itself. It works fine, except when I close the application and Thread is running. This is where the "Runtime 216" error occurs.
Details:
- In Thread creation it is set to
FreeOnTerminate
; - If there is only one component (visual indicator) in
form
, I can close the application. The problem occurs when there is more than one component;
Here's some code snippet:
constructor TWThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FreeOnTerminate := True;
oQryThread := TTIQuery.Create(nil);
oCdsThread := TClientDataSet.Create(nil);
oDBThread := TTIDatabase.Create(nil);
end;
procedure TTIWidget.EventoOnTerminate(Sender: TObject);
begin
if Assigned(oThread.oQryThread) then
begin
if oThread.oQryThread.Active then
oThread.oQryThread.Close;
FreeAndNil(oThread.oQryThread);
if Assigned(oThread.oCdsThread) then
FreeAndNil(oThread.oCdsThread);
if Assigned(oThread.oDBThread) then
FreeAndNil(oThread.oDBThread);
end;
oThread := nil;
end;