Access Violation terminating thread containing OLEvar
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;
...I have set the FreeOnTerminate to TRUE during creation
...No override in the DoTerminate event
...Critical sections are around all areas which access Non-local
variables and objects and no confilcts occur in those areas.
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...
The execute method works fine and the Excel object is released 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, releases the Excel Object and procedes with termination... But I
get an access violation when it terminates. 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 tgri...@envantage.com
Information Services
Envantage Analytical Software
15585 NEO Parkway
Cleveland, OH 44128