Apache OpenOffice (AOO) Bugzilla – Issue 55913
OLE Automation Bridge doesn't convert properly a com.sun.star.lang.PropertyValue array
Last modified: 2013-02-24 21:06:22 UTC
I found this misfunctionality accessing to the OOo through OLE Automation Bridge for manipulating the toolbars. According to the API defined for a XIndexContainer implementation object, this method expects for 2 parameters: Any Object and the index where the first one must be inserted (in the underlaying data structure). The problem appears when for adding a item to a toolbar is needed to use this method, passing it a com.sun.star.lang.PropertyValue array as parameter (where it is defined the properties of a new toolbar item). Despite of following the instructions described on the Developers Guide about how to construct OOo specific objects and arrays for being used thrugh OLE Automation Bridge, the problem appears when this method was called. -ERROR REPRODUCTION- Environment: Windows XP (SP1), OOo Beta 2, a minimal VB.NET application(*) (*) Private Sub createToolbarB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles createToolbarB.Click Dim objSM As Object = CreateObject("com.sun.star.ServiceManager") Dim CoreRef As Object = objSM.CreateInstance("com.sun.star.reflection.CoreReflection") Dim classPV As Object = CoreRef.forName("com.sun.star.beans.PropertyValue") Dim aToolbarItemProp1 As Object classPV.CreateObject(aToolbarItemProp1) Dim aToolbarItemProp2 As Object classPV.CreateObject(aToolbarItemProp2) Dim aToolbarItemProp3 As Object classPV.CreateObject(aToolbarItemProp3) Dim properties As System.Array properties = System.Array.CreateInstance(aToolbarItemProp1.GetType, 3) aToolbarItemProp1.Name = "CommandURL" aToolbarItemProp1.Value = "macro:///standard.module1.TestIt" aToolbarItemProp2.Name = "Label" aToolbarItemProp2.Value = "Test" aToolbarItemProp3.Name = "Type" aToolbarItemProp3.Value = 0 properties(0) = aToolbarItemProp1 properties(1) = aToolbarItemProp2 properties(2) = aToolbarItemProp3 Dim Doc As Object Dim dummy As System.Array Dim objDummy As Object = New Object() dummy = System.Array.CreateInstance(objDummy.GetType, 0) Doc = objSM.createInstance("com.sun.star.frame.Desktop").loadComponentFromURL("private:factory/swriter", "_blank", 2, dummy) Dim LayoutManager As Object = Doc.currentController.Frame.LayoutManager LayoutManager.createElement("private:resource/toolbar/user_toolbar1") LayoutManager.showElement("private:resource/toolbar/user_toolbar1") Dim ToolBar As Object = LayoutManager.getElement("private:resource/toolbar/user_toolbar1") Dim settings As Object = ToolBar.getSettings(True) settings.insertByIndex(0, properties) '<== ERROR IS THROWN IN THIS LINE ToolBar.setSettings(settings) End Sub The message error shown by application is following: "com.sun.star.lang.IllegalArgumentException: Type must be com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >"
You have to tell the bridge what it should do with the array you send. Not completely sure about the VB-syntax, but something like the following should solve the problem Set aInfo = objServiceManager.Bridge_GetValueObject aInfo.Set("[]com.sun.star.beans.PropertyValue", properties) settings.insertByIndex(0, aInfo)
JL->SW: I think I could enhance the bridge, so that the workaround with the value object is not necessary. Therefore I'll overtake this issue if you don't mind.
.
The problem with UNO functions which take any arguments is that the bridge has no clue as to what the implementation expects the any to contain. In case of a SAFEARRAY which is passed for example by VB, the bridge creates a Sequence of anys. This is done for SAFEARRAYs with VARIANT as element type or any other element type. Now one could argue that in the latter case, one should create a sequence of the exact type. However, this may break existing applications. Therefore I will not fix this. Using the ValueObject it is always possible to determine what the target type should be. This is also described in the developer's guide.
The Issue you raised has been marked as 'Resolved' and not updated within the last 1 year+. I am therefore setting this issue to 'Verified' as the first step towards Closing it. If you feel this is incorrect, please re-open the issue and add any comments. Many thanks, Andrew Cleaning-up and Closing old Issues ~ The Grand Bug Squash, pre v3 ~ http://marketing.openoffice.org/3.0/announcementbeta.html
As per previous posting: Verified -> Closed. A Closed Issue is a Happy Issue (TM). Regards, Andrew