2016-12-07 256 views
1

我在創建StarSuite桌面對象的實例時遇到了一些問題。 我使用了下面的標準構造,但是每當涉及到該行時:StarDesktop := StarOffice.CreateInstance('com.sun.star.frame.Desktop'); 我的StarDesktop變體保持未分配狀態。我很肯定代碼是可以的,直到那裏,但可能OpenOffice安裝的東西就搞砸了。 有沒有一種方法來檢查COM對象或沒有人有同樣的問題,並可以解決這個問題...無法創建OpenOffice桌面實例(com對象)

uses 
    ComObj; 

procedure OpenOfficeDocument; 
var 
    StarOffice: Variant; 
    StarDesktop: Variant; 
begin 
    StarOffice := CreateOleObject('com.sun.star.ServiceManager'); 
    StarDesktop := StarOffice.CreateInstance('com.sun.star.frame.Desktop'); 
    // StarDesktop is always "unassigned" 
.... 

是的,我知道。我應該更清楚地表明,我十分確定它會在正確的環境中正常工作。 但我的問題是可能是什麼原因,它不起作用。爲什麼'com.sun.star.frame.Desktop'實例未分配。我沒有選項/方式來調試它... 投票給我失望有點不公平,我研究了一個小時,但沒有找到解釋爲什麼它不起作用的東西。 或者如何以及在哪裏檢查Office安裝是否有問題(我已經卸載並重新安裝了兩次「 」我再次明白,這對別人很有用,通常會爲我工作,但是我的系統出了問題,而我想知道一些幫助來點我的方向可能是錯誤的系統(而不是在代碼示例...)

+0

的StarSuite中的ServiceManager是CreateOleObject後分配! – Niels

+1

PLZ不要使用註釋來解決問題 - 編輯問題並更新文本。 –

+1

您可以嘗試使用SysInternals進程監視器來查看嘗試創建桌面的哪些註冊表項文件,以及在嘗試創建桌面時使用哪個結果 –

回答

1

是在客戶端安裝了OpenOffice的? 不拋出任何異常?

我正在使用Bernard MarcellyDelphi 7 OOo tool和你能看到他那樣的代碼;

var 
    OpenOffice, StarDesktop: Variant; 

... 
    OpenOffice:= CreateOleObject('com.sun.star.ServiceManager'); 
    if isNullEmpty(OpenOffice) then Raise Exception.Create('OpenOffice connection is impossible'); 
    StarDesktop:= OpenOffice.createInstance('com.sun.star.frame.Desktop'); 
    if isNullEmpty(Result) then Raise Exception.Create(Format('Impossible to create service : %s', ['com.sun.star.frame.Desktop'])); 
... 

「一些常量轉換成字符串」

所以,如果則由StarDesktop空,可能無法訪問吳桌面服務。如果OpenOffice安裝正確,某些功能可能會丟失,必須設置選項。

+0

我建議; 1-)在另一個安裝了OpenOffice的客戶端上嘗試你的代碼。 2-)嘗試我們的例子在你的客戶端。 所以你可以理解是關於你的電腦的問題? 和 3 - 卸載您的openoffice並重試。如果症狀相同(StarDesktop爲空),您可以懷疑您的安裝(可能是您可以下載另一個OpenOffice版本)。我知道這不是解決方案,但是爲了解決問題,您應該縮小圈子。至少直到有人得到答案。 –

1

這對我的作品(在我的應用程序):

class procedure TOpenOffice.Connect; 
begin 
    if IsConnected then 
    Exit; 
    try 
    FServiceManager := CreateOleObject('com.sun.star.ServiceManager'); 
    except 
    FServiceManager := Null; 
    end; 
    if VarIsNull(FServiceManager) then 
    raise EOpenOfficeException.Create(StrConnectionFailed); 
    FDesktop := CreateService('com.sun.star.frame.Desktop'); 
    FDispatchHelper := CreateService('com.sun.star.frame.DispatchHelper'); 
    FIntrospection := CreateService('com.sun.star.beans.Introspection'); 
    FReflection := CreateService('com.sun.star.reflection.CoreReflection'); 
end; 

和:

class function TOpenOffice.CreateService(const ServiceName: string): Variant; 
begin 
    Result := FServiceManager.createInstance(ServiceName); 
    if VarIsNull(Result) then 
    raise EOpenOfficeException.CreateFmt(StrCouldNotCreateService,  
     [ServiceName]); 
end;