I've written an application that calls Excel 95 as a "scratchpad calculator." That is, I have a database where one field contains a (usually) properly formatted Excel formula, I pass that formula to Excel via the (via the clipboard, to be able to enter formulas between 256 and 1024 characters in length) and then read the cell back to get the result. I then store the result into another field in the table. For a simple example:
Clipboard.asText := '=AVERAGE(1,2,3)'
TheResult := ExcelObject.Range('A1:A1').value;
This works fine. As I loop through the database, however, the time per execution increases: what starts out at about 3 seconds per 10 calls gradually increases to about 10-15 seconds per 10 calls. Sooner or later, I get an OLE error saying "The remote procedure call failed" in the result fields of several records, and then it just quits.
What's going on here? Am I somehow leaking resources? How can I resolve this so that execution keeps up its speed and doesn't punk out?
Later on in the app, I open Word to do a mail-merge based on the resulting data, and this starts off working fine also. It uses ODBC to get to the Interbase table that's holding the data. After merges of about 35 small-to-middling document templates -- all of which I close when finished -- I got an OLE error message "The server threw an exception" and it hung up, forcing me to re-boot. (I'll refrain from describing what it was I wanted to throw.) In doing so, I discovered that Word was still open on the problematic file, but inivisible, so I couldn't get to see what was going on.
Any help with either/both of these problems would be greatly appreciated.