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

what is substitution for queryInterface in C#

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
kumarvidhani
General User
General User


Joined: 06 Nov 2008
Posts: 8

PostPosted: Mon Nov 10, 2008 8:25 pm    Post subject: what is substitution for queryInterface in C# Reply with quote

Hi,
Like in java we have queryInterface to get reference to an interface. Is there any
such function in C#?
Directly type cast is working but not in all the cases.

Here is my code :

XComponent xComponent = componentLoader.loadComponentFromURL(
"file:///C:/Kumar/openofficefiles/test1.ott",
"_blank", 0,
loadArgs
);


((unoidl.com.sun.star.text.XTextDocument)xComponent).
getText().setString("Taking Ott document and writing odt document!");

XBookmarksSupplier xBookmarkSupplier = (XBookmarksSupplier)xComponent;

XNameAccess xNamedBookmarks = xBookmarkSupplier.getBookmarks();

Object bookmark = xNamedBookmarks.getByName("first");

XTextContent xBookmarkContent = (unoidl.com.sun.star.text.XTextContent)bookmark;
XTextRange xTextRange = xBookmarkContent.getAnchor();
xTextRange.setString("Replacing first bookmark");


The line
XTextContent xBookmarkContent = (unoidl.com.sun.star.text.XTextContent)bookmark;
is giving problem because bookmark is object of type "uno.any"

if you print the bookmark object using toString method of object then it is showing
uno.any { unoidl.com.sun.star.XTextContent, blah blah some weird string}

so it contains XTextContent reference but still it is giving illegal type case exception
Back to top
View user's profile Send private message
hol.sten
Super User
Super User


Joined: 14 Nov 2004
Posts: 3533
Location: Hamburg, Germany

PostPosted: Tue Nov 11, 2008 11:38 am    Post subject: Reply with quote

Give this thread a try: http://www.oooforum.org/forum/viewtopic.phtml?t=23306&highlight=bookmark. Especially the C# example from pitonyak. It contains this lines:
Code:
            object oMark = Invoke(oBookmarks, "getByIndex", n);
            x = Invoke(oMark, "getName", new object[0]);
            System.Console.WriteLine((string) x);

The second line looks to me (although I have virtually no knowledge of C#), that it tries to get the name of a bookmark through Invoke(). Perhaps you can use something like that, too.
Back to top
View user's profile Send private message
kumarvidhani
General User
General User


Joined: 06 Nov 2008
Posts: 8

PostPosted: Thu Nov 13, 2008 6:02 am    Post subject: Reply with quote

thanks for reply but it does not seem to be C#
Back to top
View user's profile Send private message
woung
General User
General User


Joined: 13 Nov 2008
Posts: 7
Location: Germany, N├╝rnberg

PostPosted: Thu Nov 13, 2008 6:19 am    Post subject: uno.Any is quite easy to use... Reply with quote

Hi,

try something the following way:

uno.Any bookmark = xNamedBookmarks.getByName("first");
...
// Check if a valid value was returned
if (bookmark.hasValue())
{
// Use the value-property of Any to work with the requested instance
XTextContent xBookmarkContent = bookmark.Value as XTextContent;
// Just to be sure: check the instance
if (xBookmarkContent != null)
{ ...
}
}
_________________
All the best,
W.U.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API 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