[Solved] [Cpp] Cast problem with XReaplaceable.replaceAll()

The Application Programming Interface and the OASIS Open Document Format

[Solved] [Cpp] Cast problem with XReaplaceable.replaceAll()

Postby hr87 » Fri Mar 25, 2011 11:06 am

Hi,
I want to search and replace predefined tags in an office writer document using this code:
Code: Select all   Expand viewCollapse view
Reference < XTextDocument > xTextDocument (xComponent, UNO_QUERY);
Reference< XText > xText = xTextDocument->getText();

Reference < XReplaceable > xReplaceable(xTextDocument, UNO_QUERY);
Reference < XReplaceDescriptor > xReplaceDescriptor = xReplaceable->createReplaceDescriptor();

xReplaceDescriptor->setSearchString(OUString::createFromAscii("<tag>"));
xReplaceDescriptor->setReplaceString(OUString::createFromAscii("replace"));
xReplaceable->replaceAll(xReplaceDescriptor);


Compiling this, I get the error, that replaceAll() needs a XSearchDescriptor as argument.
error: no matching function for call to ‘com::sun::star::util::XReplaceable::replaceAll(com::sun::star::uno::Reference<com::sun::star::util::XReplaceDescriptor>&)’
/usr/include/openoffice/com/sun/star/util/XReplaceable.hdl:26: note: candidates are: virtual sal_Int32 com::sun::star::util::XReplaceable::replaceAll(const com::sun::star::uno::Reference<com::sun::star::util::XSearchDescriptor>&)

But in Java this code works fine:

Code: Select all   Expand viewCollapse view
xReplaceDescriptor.setSearchString("<tag>");
xReplaceDescriptor.setReplaceString("");
xReplaceable.replaceAll(xReplaceDescriptor);

Does anyone know, what's to do or how I have to cast the XReplaceDescriptor into a XSearchDescriptor?
Last edited by hr87 on Fri Mar 25, 2011 4:18 pm, edited 1 time in total.
OpenOffice 3.2 on Ubuntu 10.10
hr87
 
Posts: 2
Joined: Fri Mar 25, 2011 10:46 am

Re: [Cpp] Cast problem with XReaplaceable.replaceAll()

Postby hr87 » Fri Mar 25, 2011 4:18 pm

Got it.
I had to use the get-method:
Code: Select all   Expand viewCollapse view
Replaceable->replaceAll(xReplaceDescriptor.get());
OpenOffice 3.2 on Ubuntu 10.10
hr87
 
Posts: 2
Joined: Fri Mar 25, 2011 10:46 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 0 guests