Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot Close Excel Automation Process

Status
Not open for further replies.

6volt

Programmer
Jun 4, 2003
74
US
For the past 3+ years, I have successfully closed XL automation processes with the following last 4 lines of code.

Now, the process won't close.

Any thoughts?
Thanks in advance.
Tom


PC, WinXPpro, Delphi 7:

TYPE
XLap : OLEvariant; // Original Code
...
BEGIN
XLap := CreateOleObject('Excel.Application');

...do stuff here...

// CLOSE PROCESS:
XLap.quit;
XLap:='';
XLap:=Unassigned;
FreeAndNil (XLap);
 
Try this...
Code:
TYPE
   XLap : OLEvariant;  // Original Code
   ...
BEGIN
  try 
    XLap := CreateOleObject('Excel.Application');

    ...do stuff here...

  finally
    // CLOSE PROCESS:
    XLap.quit;
    XLap:='';
    XLap:=Unassigned;
    FreeAndNil (XLap);
  end;
end;
My guess is that something changed (introducing a bug) within "...do stuff here..." causing it to jump to the final end.

Also, I'm not sure that you need all 4 of your "CLOSE PROCESS:", but I dont have delphi open at the moment.

The point is, the "try/finally" block will ensure that your "CLOSE PROCESS" get's called.


HTH



Roo
Delphi Rules!
 
Roo,

I've also tried commenting out the "...do stuff here..." so that I go directly from the CREATEoleOBJECT to XLap.QUIT and still have the EXCEL.EXE process left over. Also, when debugging, I'm definitely executing the closing statements. And I've checked that the debugging environment is suitable to close the roque EXCEL.EXE Process by demonstrating that in a simple test problem.

I have another program that automates XL that doesn't do this and also a little test program that doesn't do this.

I'm in the process of single stepping through the closing statements to compare the steps taken through the system and assembler code to see what is different.

I have already done this and there is a different path taken, however, that path is so complicated, I'm going to have to log it for both cases (ugh) and hope that it will reveal the problem.
__________________

Also, this troublesome program is around 3000 lines long and there are 2 other subsequent XL automations. Since I am debugging the 1st automation, I was hoping that anything downstream would be of no importance, however, I'm not sure of that.
____________________

I'm also wondering about the tree structure of Procs and Funcs that involve XL and how EXCEL97, COMOBJ, and OLESERV are ordered in the USES statements. So far, a few changes have not solved problem.
_____________________

I keep thinking of changes to try but I am quickly coming to the end of ideas which will leave only the brute force method where I start building a copy of the program, step by step, until I hit the snag that causes this problem. I am not looking forward to that.

Thanks for you input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top