jgreif General User

Joined: 02 Sep 2005 Posts: 8
|
Posted: Wed Nov 16, 2005 12:04 am Post subject: StarDesktop.terminate() fails when loadComponentFromURL fail |
|
|
This is a variant of discussions in other posts, but seems different. It occurs in OpenOffice.org 1.9.125 and 2.0 This code snippet, contained in a macro executed in an -invisible soffice executed from the command line,
| Code: | On Local Error GoTo leaveWriteError
' Open the document.
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(_
MakePropertyValue( "Hidden", True ),_
) )
If (Not oDoc.supportsService("com.sun.star.sheet.SpreadsheetDocument"))_
Then
WriteErrorFile(2, "Non-spreadsheet input type.", cErrFile )
GoTo closeIt
End If
cFile = Left( cFile, Len( cFile ) - 4 ) + ".ods"
cURL = ConvertToURL( cFile )
' Save the document in standard format.
oDoc.storeToURL( cURL, Array())
closeIt:
oDoc.close( True )
StarDesktop.Terminate()
Exit Sub
leaveWriteError:
WriteErrorFile(Err, Error$, cErrFile)
leave:
StarDesktop.Terminate()
Exit Sub
| works fine when loadComponentFromURL succeeds. When loadComponentFromURL does not succeed, an error does not occur. Instead, apparently oDoc is not set. (In the API, NULL is supposed to be returned.) Then the oDoc.supportsService(...) gets an error (91, "Object variable is not set") as dumped into the error file at the label leaveWriteError. But after Terminate() the soffice.bin process hangs around in a wedged state. No other attempts to do anything in open office 2.0 will succeed.
I defend against one kind of failure of loadComponentFromURL by checking for the existence of the file before reaching the code above. However, if someone renames a .doc file as .xls, loadComponentFromURL will fail in the way described above. (In the OpenOffice GUI, a message box appears saying something like Read error if you try to open this misnamed document, but it is possible to exit the application.)
My suspicion is that some XComponent is created (partially?) even though loadComponentFromURL fails, and this unclosed document prevents termination.
I have these questions:
1. If I do Dim x as Object, is there some way to test whether x has been set?
2. Should I try to call StarDesktop.getCurrentComponent() and close() or dispose() it after loadComponentFromURL fails, in order to get a handle on the wedged thing?
3. Should I try to iterate through StarDesktop.getAllComponents() and close or dispose them to accomplish the same thing?
4. Is there any other way to guarantee, from within a macro, that the soffice.bin process will exit?
i have good reasons not to communicate with a long-running OOo server through the API, but rather to run a new process for each document conversion.
Jeff |
|