Delphi 2 access violation at thread termination
I have a background thread (TThread class) which writes processed data
to an
Excel workbook. I have structured the execute method as follows....
procedure TXLReportThread.Execute;
begin
repeat
While RunIt do
begin
OLEInitialize(nil);
XLServer:=CreateOLEObject('Excel.application');
XLServer.DisplayAlerts:=false;
XLServer.visible:=false;
XPRC:=CurrentPRC^;
ReportToExcel;
XLServer.quit;
OLEUninitialize;
RunIt:=false;
end;
if terminated then Closeit:=true;
until Closeit;
end;
The thread is created at application startup and suspended until I
resume it
and call the RUN method which sets RunIt to true and allows the
execution to
begin...(I have critical sections around all areas which access
Non-local
variables and objects and have had no conflicts there)
The execute method works fine and the Excel object is release properly
when I
call its QUIT method.. Also subsequent resumes and suspend work fine...
I terminate the thread by calling its CLOSE method which sets CloseIt to
true
and procedes with termination...(No override in the DoTerminate event)
But I get
an access violation when it terminates. (I have set the FreeOnTerminate
to true
during creation) Once I hit OK at the violation message, the application
then
exists normally....
I have tried everything I can think of to correct this but to no
avail...Does
anyone have any thoughts?
Thanks,
Tom Grills tgrills@^RemoveThis^envantage.com
Information Services
Envantage Analytical Software
15585 NEO Parkway
Cleveland, OH 44128