Home computickets Working with Excel in Delphi (memory cleaning)

Working with Excel in Delphi (memory cleaning)

Author

Date

Category

I work with Excel in Delphi 7 via OLE. How to create a file, change something in it and close it, there are no problems. But I also need to open the Excel file saved in the database (MSSQL) for viewing. I work with Excel like this:

ExlApp: = CreateOleObject ('Excel.Application');
try
 ExlApp.Workbooks.Open (XLSFile);
 Sheet: = ExlApp.Workbooks [ExtractFileName (XLSFile)]. WorkSheets [1];
 ...
finally
 ExlApp.DisplayAlerts: = false;
 ExlApp.ActiveWorkbook.Close (SaveChanges: = False);
 ExlApp.Application.Quit;
 Sheet: = Unassigned;
 ExlApp: = Unassigned;
end;

If we are only going to open an Excel file, then there is a piece of code:

ExlApp.DisplayAlerts: = false;
 ExlApp.ActiveWorkbook.Close (SaveChanges: = False);
 ExlApp.Application.Quit;
 Sheet: = Unassigned;
 ExlApp: = Unassigned;

will be absent, then do you need to clear the memory (when the user closes the Excel document) allocated for ExlApp and if so, how?


Answer 1, authority 100%

In fact, it should have been written like this:

try
...
finally
 ExlApp.Visible: = True;
 Sheet: = Unassigned;
 ExlApp: = Unassigned;
end;

We free memory and the program continues to run. And the user will close the Excel document when he sees fit.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions