Mathias Bauer and All
SlumberMan wrote:

Hi, All
I try to use com::sun::star::frame::XStorable interface in a cpp source file, which is written by myself. I add the line "using namespace com::sun::star::frame;" at top and try to invoke a reference of XStorable by the following line:
Reference < XStorable > xSave ( xComponent, UNO_QUERY );
But the compiler says that, error: ‘XStorable’ was not declared in this scope.

You didn't mention that you included <com/sun/star/frame/XStorable.hpp>
in your file. Perhaps you forgot to do that?

Yes, I missed this line. I didn't find it in directory */opt/openoffice/basis-link/sdk/include* at first. And now I figure out that it is in *~/opneoffice.org3.1_sdk/LINUXexample.out/inc* directory.
I have a little wonder why put these apart.

ps. My system is Linux 2.6.29-ARCH x86_64
There's only example code in Java in Developer's Guide book and OOo Wiki.
Could anybody give me some hint about how to save a document which is opened by XComponentLoader::loadComponentFromURL() in cpp language.

>From the top of my head, without having compiled it and whithout writing
down the complete code for creating the desktop object and without any
handling of exceptions:

#include <rtl/ustring.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>

using namespace com::sun::star;

// add code to create Desktoo object
uno::Reference < frame::XDesktop > xDesktop;

// properties for loading might be added here
uno::Sequence < beans::PropertyValue > aProps;

// example file name
::rtl::OUString aFileName =     
    :rtl::OUString::createFromAscii("file:///home/user/myfile.odt");

// create new window
::rtl::OUString aTargetFrame = rtl::OUString::createFromAscii("_blank");

uno::Reference < frame::XStorable >
    xStor( xDesktop->loadComponentFromURL( aFileName, aTargetFrame, 0,
    aProps ), uno::UNO_QUERY );

// more properties for storing might be added here
uno::Sequence < beans::PropertyValue > aStoreProps(1);
aStoreProps[0].Name = ::rtl::OUString::createFromAscii("Overwrite");
aStoreProps[0].Value <<= sal_True;

// example file name for storing
::rtl::OUString aFileName =     
    :rtl::OUString::createFromAscii("file:///home/user/mynewfile.odt");

xStorable->storeToURL( aNewFile, aStoreProps );

Some of the includes may be superfluous as they might be nested into
others anyway. Please watch that runtime library headers are included as
"hxx", while API headers have the extension "hpp".

I recommend to send questions like this to the "dev" or "d...@api" list
in future.

Regards,
Mathias
The example here helps a lot. Thank you kindly!
Best regards.

--
===========================================
Yuelin Zhuang   --   Testing 3, RedFlag2000
MSN :                 [email protected]
E-mail:          [email protected]
===========================================


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to