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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
hr87
Posts: 2
Joined: Fri Mar 25, 2011 10:46 am

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

Post by hr87 »

Hi,
I want to search and replace predefined tags in an office writer document using this code:

Code: Select all

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

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()

Post by hr87 »

Got it.
I had to use the get-method:

Code: Select all

Replaceable->replaceAll(xReplaceDescriptor.get());
OpenOffice 3.2 on Ubuntu 10.10
Post Reply