| View previous topic :: View next topic |
| Author |
Message |
kumarvidhani General User

Joined: 06 Nov 2008 Posts: 8
|
Posted: Mon Nov 10, 2008 8:25 pm Post subject: what is substitution for queryInterface in C# |
|
|
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 |
|
 |
hol.sten Super User


Joined: 14 Nov 2004 Posts: 3532 Location: Hamburg, Germany
|
Posted: Tue Nov 11, 2008 11:38 am Post subject: |
|
|
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 |
|
 |
kumarvidhani General User

Joined: 06 Nov 2008 Posts: 8
|
Posted: Thu Nov 13, 2008 6:02 am Post subject: |
|
|
| thanks for reply but it does not seem to be C# |
|
| Back to top |
|
 |
woung General User

Joined: 13 Nov 2008 Posts: 7 Location: Germany, Nürnberg
|
Posted: Thu Nov 13, 2008 6:19 am Post subject: uno.Any is quite easy to use... |
|
|
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 |
|
 |
|