OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to solve this : ActiveX component can't create object

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
neltik
General User
General User


Joined: 16 Jun 2004
Posts: 5
Location: Malaysia

PostPosted: Wed Jun 16, 2004 5:24 pm    Post subject: How to solve this : ActiveX component can't create object Reply with quote

Halo,
I'm writing a VisualBasic component to automate OOo Calc in drawing charts. I followed the guide in "StarOffice Programmerís Tutorial" and created a few objects required to add a new chart. Here's the code :
Code:
Set objServiceManager = CreateObject("com.sun.star.ServiceManager")
Set chartArea = objServiceManager.createInstance("com.sun.star.awt.Rectangle")
Set addressRange(0) = CreateObject("com.sun.star.Table.CellRangeAddress")'<--Problem here

VisualBasic gave me an error ("ActiveX component can't create object") and highlighted the 3rd line as the cause. What is the correct way to create that object? I've tried creating an instance using the ServiceManager, but it doesn't work. Please help.
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Wed Jun 16, 2004 8:22 pm    Post subject: Reply with quote

CreateObject is only used to instantiate the OLE Bridge (ActiveX is embedded in OLE) to the ServiceManager.
All services like com.sun.star.table.CellRangeAddress can then be accessed via the ServiceManager's method createInstance.
In your example this would mean:
Set addressRange(0) = objServiceManager.createInstance("com.sun.star.Table.CellRangeAddress")

However there is another tricky part about your call. CellRangeAddress is a UNO struct, to use this you must create a struct class object first.
I only tested my code in Python, so I don't know if it works for you in VB but according to official documentation (Developers Guide) it should:
Code:

Set reflect = objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
Set typeclass = reflect.forName("com.sun.star.Table.CellRangeAddress")
Dim cellrange REM first we have to define an object/a variable to which the typeclass is assigned to

typeclass.createObject(cellrange) REM and now we have the variable as a struct type, note that it's a oneway call

cellrange.Sheet = 1
cellrange.StartColumn = 1
REM etc. etc.


For further information please take a look at:
http://api.openoffice.org/docs/DevelopersGuide/ProfUNO/ProfUNO.htm#1+4+4+Automation+Bridge and
http://udk.openoffice.org/common/man/tutorial/office_automation.html.


Hope that helps.
Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Thu Jun 17, 2004 1:13 am    Post subject: Reply with quote

Thanks, Cristian. Your code has switch on the 'light bulb' above my head.

Yes, your code does work in VB, but since the CoreReflection forName( ) method returns an UNO struct, I can't seem to Dim a correct variable to accept it. I know I've got the object, but VB keep telling me "Type mismatch" when I tried to assign it to a variable.

I've found an alternative by using Bridge_GetStruct( ) method. I got this from the link that you've provided (Thanks again!). VB accepts the returned product without complain.

Here's the code :
Code:

Dim addressRange(0)
Set addressRange(0) = objServiceManager.Bridge_GetStruct("com.sun.star.table.CellRangeAddress")


Thanks.
Back to top
neltik
General User
General User


Joined: 16 Jun 2004
Posts: 5
Location: Malaysia

PostPosted: Thu Jun 17, 2004 1:16 am    Post subject: Reply with quote

Sorry, typo :
Thanks, Christian.
Wink
Back to top
View user's profile Send private message
neltik
General User
General User


Joined: 16 Jun 2004
Posts: 5
Location: Malaysia

PostPosted: Tue Jun 22, 2004 6:22 pm    Post subject: Error : InterfaceOleWrapper_Impl::Invoke : ... Reply with quote

Halo,

Does anyone know what's the correct way to cast an object type? I would like to print a document using VB automation, but can't seem to get the right object to provide the service.

With the code below :
Code:

Set objXPrintableClass = objServiceManager.createInstance("com.sun.star.view.XPrintable.class")
Set objTypeClass = objCoreReflection.forName("com.sun.star.view.XPrintable")
objTypeClass.CreateObject (objXPrintable)
Set objXPrintable = objServiceManager.QueryInterface(objXPrintableClass, objDocument)


I get the following error message in VB :
Quote:

Run-time error '1001':

InterfaceOleWrapper_Impl::Invoke :
[automation bridge]UnoConversionUtilies<T>::variantToAny
Cannot convert the value of vartype :"9" to the expected UNO type
of type class: -575168071


VB highlighted the last line as the fault. I was trying to print the document using the Print method from the XPrintable interface.

In another case, with the code below :
Code:

Set objMailService = objServiceManager.createInstance("com.sun.star.system.SimpleSystemMail")
Set objMail = objMailService.querySimpleMailClient()
Set objMessage = objMail.createsimplemailmessage()
Set arg2 = objServiceManager.createInstance("com.sun.star.System.SimpleMailClientFlags.NO_USER_INTERFACE")
objMail.sendSimpleMailMessage objMessage, arg2


I get a similar error message :
Quote:

Run-time error '1001':

InterfaceOleWrapper_Impl::Invoke :
[automation bridge]UnoConversionUtilies<T>::variantToAny
Cannot convert the value of vartype :"13" to the expected UNO type
of type class: 6


VB highlighted the 3rd line (Set arg2 = ...) as the cause

I'm guessing that I need some type casting in assigning the object to the variables. I've tried using CoreReflection->forName->CreateObject method, but it isn't working (or I'm not using it correctly??). I've also tried the Bridge_GetStruct method, and it's not working either. Any suggestions?
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Tue Jun 22, 2004 6:59 pm    Post subject: Reply with quote

Quote:
Code:
Set objXPrintableClass = objServiceManager.createInstance("com.sun.star.view.XPrintable.class")
Set objTypeClass = objCoreReflection.forName("com.sun.star.view.XPrintable")
objTypeClass.CreateObject (objXPrintable)
Set objXPrintable = objServiceManager.QueryInterface(objXPrintableClass, objDocument)


I see a lot of things here, that are not correct. Firstly I don't see why you would use QueryInterface(...), this method is only done with Java, as Java has to get the interfaces first to do some action with an object.
Secondly, cause it doesn't show in your first code: Did you define objXPrintable as Variant before? Usually I would just insert the declaration "Set objXPrintable" before the line objTypeClass.CreateObject(objXPrintable).
And thirdly and that's a very major thing: the CoreReflection service is used for creating/modifying OOo API types, now what you're doing here is you try to create a corresponding type which you would get/have when getting the Interface XPrintable.
Obviously this is an interface, an interface has methods it doesn't provide or reflect specific types for you!
I suggest that you read more of the concepts cause this is a logical error.
If I am now telling you how to do it correctly you might not be looking into the concepts, which wouldn't be very good for you if you want to resume working with the API.
Read yourself through topics about Types in the API, you'll then get the main idea behind it I think.
If you absolutely need the correct code fastly then answer me and I will provide the correct code for you.


I hope this is okay for you. And if you can't find good documentations, then let me know, I can give you some.

Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
neltik
General User
General User


Joined: 16 Jun 2004
Posts: 5
Location: Malaysia

PostPosted: Tue Jun 22, 2004 10:19 pm    Post subject: Reply with quote

Er, yup... I think you got me there. Those codes were translated from the references (in OpenOffice 1.1 Developer's Guide, and others) from Java syntax to VB.
Code:

//query the XPrintable interface from your document XPrintable xPrintable =(XPrintable)UnoRuntime.queryInterface(XPrintable.class,xDoc);
//create an empty printOptions array PropertyValue [] printOpts ==new PropertyValue [0 ] ;
//kick off printing xPrintable.print (printOpts);

I thought I would get things done faster this way... as a result, I don't really have a good grip of the whole OOo API framework.
But since I've got my head so far down to getting OOo APIs to work with VB, I think it's worth to read up more on the concepts. I'll get back to you later... after I've understand about the objects and interfaces. And yes, I would appreciate it if you can provide some links to documentation for Windows users.
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Wed Jun 23, 2004 10:35 am    Post subject: Reply with quote

I suggest that you start reading chapter 2 of the Developer's Guide (read the whole chapter, it's an excellent introduction to UNO).
Not a bad idea is also to download the StarOffice Programmer's Guide at http://docs.sun.com/db/doc/817-1826?q=StarOffice, although it is intended for OOoBasic, it also contains some very good parts on the API itself. I would read whatever you find useful in the first 3 chapters.
And then if you have understood everything about types I would take the final approach with the following two links, I posted before:
http://api.openoffice.org/docs/DevelopersGuide/ProfUNO/ProfUNO.htm#1+4+4+Automation+Bridge and
http://udk.openoffice.org/common/man/tutorial/office_automation.html

For the first one I would take some time, because there your specific task is clearly explained (accessing OOo via COM/OLE Automation Bridge).

Of course:
It's all up to you how much time you spend on it, maybe you'll take less than 30 minutes for it maybe you want to delve into it and read more than 3 hours.

For specific things I would go to http://api.openoffice.org or http://udk.openoffice.org these project sites contain a lot of spec documentations and you can always search for specific issues through their dev-mailinglists.

That should be enough Smile

Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group