Groups > Borland > Borland C plus plus builder Active X > Re: Excel not released after using TExcelApplication




Excel not released after using TExcelApplication

Excel not released after using TExcelApplication
Wed, 18 Jul 2007 15:39:52 +020
I have following problem: look at this example:

This creates a new Excel worksheet and saves it as "c:\test.xls".

void __fastcall TExcelSim::SimpleTest(void)
{
    TExcelApplication *ea;
    TExcelWorksheet *ew;
    TExcelWorkbook *eb;
    ea = new TExcelApplication(this);
    ew = new TExcelWorksheet(this);
    eb = new TExcelWorkbook(this);

    ea->Connect();
    eb->ConnectTo(ea->Workbooks->Add());
    ew->ConnectTo(eb->Worksheets->Add());
   
eb->SaveAs(TVariant("c:\\test.xls"),TNoParam(),TNoParam(),TNoParam(
),TNoParam(),TNoParam(),xlNoChange,TNoParam(),TNoParam(),TNoParam(),TNoParam(),L
OCALE_SYSTEM_DEFAULT) 
;
    ew->Disconnect();
    eb->Disconnect();
    ea->Disconnect();
    delete eb;
    delete ew;
    delete ea;
}

At the end there are three situations:

1.    If the SaveAs is commented (//) the EXCEL task is removed from memory. 
Correct.
2.    If the SaveAs is not commented and the file "c:\test.xls" does
not 
exist, or if it exists and we confirm to overwrite it, the EXCEL task 
remains active at the end. *** Why? ***
3.    If the SaveAs is not commented and the file exists and we do not 
confirm to overwrite it, the EXCEL task is removed from memory.

Any idea why the point [2] happens?

Post Reply
Re: Excel not released after using TExcelApplication
Thu, 19 Jul 2007 11:27:55 +040
On Wed, 18 Jul 2007 15:39:52 +0200, "Alessandro Cipriano"
<sXaXnXdXi@nospam.iol.it> wrote:

>Any idea why the point [2] happens?

not sure whether it is related to your problem or not but there are
bugs in borland provided ms-office wrappers. for example see the
change I had to implement in word_xp_srvr.cpp:

void __fastcall TWordApplication::Disconnect()
{
  if(bool(m_DefaultIntf))
  {
    if(AutoQuit)
    {
      Quit();
    }
....
  }
}

-- 
Post Reply
about | contact