Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: OleContainer save as RTL format


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: May 27, 2016 1:28 PM Last Post By: Remy Lebeau (Te...
Nagy Gabor

Posts: 3
Registered: 9/19/08
OleContainer save as RTL format  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 26, 2016 8:17 AM
Hi all,

I open a new wordpad document with OleContainer, this is ok, but I don't know how to save this document in RTF format.

I Open a new wordpad:
OleContainer1->CreateObject("WordPad.Document.1",false);
OleContainer1->DoVerb(ovShow);

So I tried to save:
OleContainer1->SaveAsDocument("d:
test.rtf");


This code created the d:\test.rtf file with OleContainer Header..
How to save in RTF format with rtf header?

I found an example in Delphi code:
OLEContainer1.OLEObject.SaveAs(FileName := 'C:\arb.RTF', FileFormat := wdFormatRTF);

How to use this code in C++ builder?
OleContainer1->OleObject-> NOT SAVEAS option....

Please help!

Thanks!

Edited by: Nagy Gabor on May 26, 2016 8:17 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: OleContainer save as RTL format [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 26, 2016 10:41 AM   in response to: Nagy Gabor in response to: Nagy Gabor
Nagy wrote:

I found an example in Delphi code:

*OLEContainer1.OLEObject.SaveAs(FileName := 'C:\arb.RTF', FileFormat :=
wdFormatRTF);*

How to use this code in C++ builder?
OleContainer1->OleObject-> NOT SAVEAS option....

The OleObject property returns a Variant holding the OLE object's IDispatch
interface. Delphi's pascal language has built-in support for late binding
of COM/OLE method calls, thus allowing OLE methods to be called directly
on Variant and IDispatch variables. They are ultimately just high-level
wrappers around the IDispatch.Invoke() method. C++ does not have that same
built-in late-binding support, you would have to call IDispatch::Invoke()
directly. However, the Variant class can handle that for you, eg:

// FileName and FileFormat are the first two parameters of SaveAs(),
// so just provide their values by their parameter order...
OLEContainer1->OleObject.OleProcedure("SaveAs", WideString("C:\\arb.RTF"), 
6/*wdFormatRTF*/);


Alternatively:

// or you can provide the FileName and FileFormat values by their parameter 
names...
Procedure SaveAs("SaveAs");
SaveAs << NamedParm("FileName", "C:\\arb.RTF") << NamedParm("FileFormat", 
6/*wdFormatRTF*/);
OLEContainer1->OleObject.Exec(SaveAs);


--
Remy Lebeau (TeamB)
Nagy Gabor

Posts: 3
Registered: 9/19/08
Re: OleContainer save as RTL format [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2016 5:25 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi,

thanks for your reply.
I tried both method earlier, but not it work.
"Project1.exe raised exception class EIntfCastError with message 'Interface not supported'"...
Any idea?
Thanks!

Remy Lebeau (TeamB) wrote:
Nagy wrote:

I found an example in Delphi code:

*OLEContainer1.OLEObject.SaveAs(FileName := 'C:\arb.RTF', FileFormat :=
wdFormatRTF);*

How to use this code in C++ builder?
OleContainer1->OleObject-> NOT SAVEAS option....

The OleObject property returns a Variant holding the OLE object's IDispatch
interface. Delphi's pascal language has built-in support for late binding
of COM/OLE method calls, thus allowing OLE methods to be called directly
on Variant and IDispatch variables. They are ultimately just high-level
wrappers around the IDispatch.Invoke() method. C++ does not have that same
built-in late-binding support, you would have to call IDispatch::Invoke()
directly. However, the Variant class can handle that for you, eg:

// FileName and FileFormat are the first two parameters of SaveAs(),
// so just provide their values by their parameter order...
OLEContainer1->OleObject.OleProcedure("SaveAs", WideString("C:\\arb.RTF"), 
6/*wdFormatRTF*/);


Alternatively:

// or you can provide the FileName and FileFormat values by their parameter 
names...
Procedure SaveAs("SaveAs");
SaveAs << NamedParm("FileName", "C:\\arb.RTF") << NamedParm("FileFormat", 
6/*wdFormatRTF*/);
OLEContainer1->OleObject.Exec(SaveAs);


--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: OleContainer save as RTL format [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2016 10:18 AM   in response to: Nagy Gabor in response to: Nagy Gabor
Nagy wrote:

thanks for your reply.
I tried both method earlier, but not it work.
"Project1.exe raised exception class EIntfCastError with message
'Interface not supported'"...

On which statement exactly? Which code method is causing the error? Or
are they both causing it? Is the OleObject variant actually holding a Dispatch
object?

Variant v = OLEContainer1->OleObject;
int vType = v.Type(); // <-- what value does this return?
if (!v.IsEmpty() && !v.IsNull()) // <-- does this evaluate to true or false?
{
    v.OleProcedure("SaveAs", WideString("C:\\arb.RTF"), 6/*wdFormatRTF*/);
 
    // or:
 
    Procedure SaveAs("SaveAs");
    SaveAs << NamedParm("FileName", WideString("C:\\arb.RTF"));
    SaveAs << NamedParm("FileFormat", 6/*wdFormatRTF*/);
    v.Exec(SaveAs);
}


--
Remy Lebeau (TeamB)
Nagy Gabor

Posts: 3
Registered: 9/19/08
Re: OleContainer save as RTL format [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2016 11:54 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
I tried this code now.
The compiler message, "OLEContainer1 undefinied symbol", so I changed to "OleContainer1". (The component name is OleContainer1 with lowercase)
The problem is always the same place:
Variant v = OleContainer1->OleObject;     //<--------Here interrupted the run ('Interface not supported' )
int vType = v.Type(); // <-- what value does this return?
if (!v.IsEmpty() && !v.IsNull()) // <-- does this evaluate to true or false?


Code1:
Procedure SaveAs("SaveAs"); 
SaveAs << NamedParm("FileName", "d:\\arb.RTF") << NamedParm("FileFormat",6/*wdFormatRTF*/);
OleContainer1->OleObject.Exec(SaveAs);       //<--------Here interrupted the run ('Interface not supported' )


Code2:
OleContainer1->OleObject.OleProcedure("Save", WideString("d:\\arb.rtf"),6/*wdFormatRTF*/);    //<--------Here interrupted the run ('Interface not supported' )


Remy Lebeau (TeamB) wrote:
Nagy wrote:

thanks for your reply.
I tried both method earlier, but not it work.
"Project1.exe raised exception class EIntfCastError with message
'Interface not supported'"...

On which statement exactly? Which code method is causing the error? Or
are they both causing it? Is the OleObject variant actually holding a Dispatch
object?

Variant v = OLEContainer1->OleObject;
int vType = v.Type(); // <-- what value does this return?
if (!v.IsEmpty() && !v.IsNull()) // <-- does this evaluate to true or false?
{
    v.OleProcedure("SaveAs", WideString("C:\\arb.RTF"), 6/*wdFormatRTF*/);
 
    // or:
 
    Procedure SaveAs("SaveAs");
    SaveAs << NamedParm("FileName", WideString("C:\\arb.RTF"));
    SaveAs << NamedParm("FileFormat", 6/*wdFormatRTF*/);
    v.Exec(SaveAs);
}


--
Remy Lebeau (TeamB)

Edited by: Nagy Gabor on May 27, 2016 11:57 AM

Edited by: Nagy Gabor on May 27, 2016 11:59 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: OleContainer save as RTL format [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 27, 2016 1:28 PM   in response to: Nagy Gabor in response to: Nagy Gabor
Hello Nagy,

The compiler message, "OLEContainer1 undefinied symbol", so I changed
to "OleContainer1".

Yes, obviously you have to use the correct object name. C++ is case-sensitive,
Delphi is not.

Variant v = OleContainer1->OleObject; //<--------Here interrupted the
run ('Interface not supported' )

Internally, TOleContainer holds a reference to the underlying OLE object
(in this case, the Wordpad Document) using an IOleObject interface.

The TOleContainer::OleObject property getter queries the IOleObject for IDispatch
and then puts that into the returned Variant.

So, the only way to get that partiular error is if that query is failing
because the OLE object does not implement IDispatch. Which I find hard to
believe, considering that the same code works in Delphi, and the underlying
OLE object would be the same regardless of which language is accessing it.
OleObject.SaveAs() would not work in Delphi if IDispatch were not available.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02