Link to home
Start Free TrialLog in
Avatar of Roger Alcindor
Roger Alcindor

asked on

Excel COM Server connection does not close

I have an application written in Embarcadero C++ builder XE2 which uses the Excel Office COM server components that ship with the compiler.

It is a simple application that opens a spreadsheet and processes data from one of the spreadsheets.
I am using 3 components (TExcelWorksheet,TExcelWorkbook and TExcelApplication)
The application functions as it should but after the application has run, the task manager reveals that the Excel.exe *32 process is still running and this results in an erro when the application is subsequently run.

The destructor in the main form of my application contains the following code which I am using to close the Excel components but it would appear that this is not working.

    ExcelWorksheet1->Disconnect();
    ExcelWorkbook1->Disconnect();
    ExcelApplication1->Quit();
    ExcelApplication1->Disconnect();

I have also tried the following:
    ExcelWorksheet1->Disconnect();
    ExcelWorkbook1->Disconnect();
    ExcelApplication1->Disconnect();
    ExcelApplication1->Quit();

Is there a way to fix this ?
Avatar of Zack Barresse
Zack Barresse
Flag of United States of America image

I'm not fluent with C++, but wouldn't you want your logic like this...

Do stuff with Excel
Quit Excel
Disconnect objects


?

Regards,
Zack Barresse
Avatar of Roger Alcindor
Roger Alcindor

ASKER

I have tried the following in the main form destructor and that doesn't fix the issue:

    ExcelApplication1->Quit();
    ExcelWorksheet1->Disconnect();
    ExcelWorkbook1->Disconnect();

In C++ the main form destructor is where you place code to clean up and free any resources that have been used in the main form, in this case it is the Excel COM components that were used.
ASKER CERTIFIED SOLUTION
Avatar of Roger Alcindor
Roger Alcindor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I discovered the fix by myself.