Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Documentation for OleFunction, OlePropertyGet etc keywords/property names?


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


Permlink Replies: 8 - Last Post: Jul 11, 2016 4:18 PM Last Post By: Gord Pollock
Kathleen Beaumont

Posts: 4
Registered: 12/1/01
Documentation for OleFunction, OlePropertyGet etc keywords/property names?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 22, 2016 10:26 AM
I am working with C++ Builder 10 Seattle, and developing a class to create reports in Word.

Using ComObj.hpp and code samples I have located on the Web, I have managed to control paragraphs and styles, insert a table, change the color of the font in the cells of the header row, etc.

What I have been unable to locate is any documentation that tells me what keywords can be used on an object. For example, I can change the color, style and size of the font in a cell of a table:

{code}
Variant t_cell = vTable.OlePropertyGet("Cell", 1.2);
// mark the beginning of the text to color
int t_start = t_cell.OlePropertyGet("Range").OlePropertyGet("End");
// write the text to the cell
t_cell.OlePropertyGet("Range").OleProcedure("InsertAfter", StringToOleStr(AValue));
// mark where we are now
int t_end = t_cell.OlePropertyGet("Range").OlePropertyGet("End");

// get a Range object for the cell contents
Variant t_range = FWordDoc.OleFunction("Range", t_start-1, t_end);

// Select the contents to modify the font
t_range.OleProcedure("Select");

t_range.OlePropertyGet("Font").OlePropertySet("Bold", true);
t_range.OlePropertyGet("Font").OlePropertySet("Color", clTeal);
t_range.OlePropertyGet("Font").OlePropertySet("Size", 14);
{code]

This works. But I really want to be able to change the background color. I've seen examples using t_cell.OlePropertySet("Interiors", [some color specifier]), and t_cell.OlePropertySet("FillColour", [some color]), but when I try those, runtime error "Unknown name" is raised.

I was directed to the Word Developer Tab and Visual Basic Object Browser to find out all the classes and members, but I can't find documentation or tutorials for that, either.

Where should a VCL user turn for documentation on Ole Automation, particularly for Word?

Edited by: Kathleen Beaumont on Jun 22, 2016 10:27 AM

Edited by: Kathleen Beaumont on Jun 22, 2016 10:27 AM

Edited by: Kathleen Beaumont on Jun 22, 2016 10:29 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Documentation for OleFunction, OlePropertyGet etc keywords/propertynames? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 22, 2016 10:45 AM   in response to: Kathleen Beaumont in response to: Kathleen Beaumont
Kathleen wrote:

What I have been unable to locate is any documentation that tells
me what keywords can be used on an object.

You are not going to find that info in C++Builder's documentation. Such
keywords are specific to the objects being accessed, so you need to refer
to their respective vendor's documentation instead.

t_cell.OlePropertyGet("Range").OleProcedure("InsertAfter", StringToOleStr(AValue));

StringToOleStr() returns an allocated BSTR, you need to free it with you
are using it:

BSTR str = StringToOleStr(AValue);
t_cell.OlePropertyGet("Range").OleProcedure("InsertAfter", str);
SysFreeString(str);


You should use the WideString class instead, which wraps a BSTR and handles
memory management for you:

t_cell.OlePropertyGet("Range").OleProcedure("InsertAfter", WideString(AValue));


I really want to be able to change the background color.

Of just the text? Or of the entire cell? Those are two different things.

I've seen examples using t_cell.OlePropertySet("Interiors", [some color
specifier]),
and t_cell.OlePropertySet("FillColour", [some color]), but when I try those,
runtime
error "Unknown name" is raised.

Where should a VCL user turn for documentation on Ole Automation,
particularly for Word?

Microsoft's Word Automation documentation on MSDN.

--
Remy Lebeau (TeamB)
Kathleen Beaumont

Posts: 4
Registered: 12/1/01
Re: Documentation for OleFunction, OlePropertyGet etc keywords/propertynames? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 22, 2016 3:09 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

You are not going to find that info in C++Builder's documentation. Such
keywords are specific to the objects being accessed, so you need to refer
to their respective vendor's documentation instead.

I truly have tried to find documentation that describes what OleFunctions can be performed on an object, as well as available properties and values for OlePropertySet. The MSDN documentation has been no help. I started here:

https://msdn.microsoft.com/en-us/library/kw65a0we.aspx

and followed the links for "Working with Text in Documents" and "Working with Tables", which does eventually lead to some task-specific examples, but if it somehow leads to per-object properties lists, I can't find it.

Thank you for the information about StringToOleStr, BSTR and the preferred WideString. I'll make corrections to my code.

I really want to be able to change the background color.

Of just the text? Or of the entire cell? Those are two different things.

Of the cell. Thanks for pointing out that the text can have a background color distinct from the cell color (I hadn't thought of that).

Where should a VCL user turn for documentation on Ole Automation,
particularly for Word?

Microsoft's Word Automation documentation on MSDN.

Okay. Once more into the fray, then.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Documentation for OleFunction, OlePropertyGet etckeywords/propertynames? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 22, 2016 4:04 PM   in response to: Kathleen Beaumont in response to: Kathleen Beaumont
Hello Kathleen,

I truly have tried to find documentation that describes what
OleFunctions can be performed on an object, as well as available
properties and values for OlePropertySet.

OleFunction, OleProperty(Get/Set), these are Borland-specific wrappers related
to the (Ole)Variant classes. Non-Borland documentation has no concept of
them.

The MSDN documentation has been no help.

Yes, it is. You just have to understand where to look and how to read it.
The information is there.


That reference is for Word's .NET interop objects for C#/VB.NET. You need
to look at the OLEAutomation/VBA reference instead, which defines objects
that C++ can access. Start here instead:

https://msdn.microsoft.com/en-us/library/office/fp179696.aspx
https://msdn.microsoft.com/en-us/library/ee861527.aspx

and followed the links for "Working with Text in Documents" and
"Working with Tables", which does eventually lead to some
task-specific examples, but if it somehow leads to per-object
properties lists, I can't find it.

Many of the links on that first page you visited are for specific objects
(Application, Document, Range, etc). But even following the other links
you visited, they do lead to object-specific links as well.

--
Remy Lebeau (TeamB)
Kathleen Beaumont

Posts: 4
Registered: 12/1/01
Re: Documentation for OleFunction, OlePropertyGet etckeywords/propertynames? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 22, 2016 5:49 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

OleFunction, OleProperty(Get/Set), these are Borland-specific wrappers related
to the (Ole)Variant classes. Non-Borland documentation has no concept of
them.

That's part of my difficulty. The syntax for using those wrappers does not match the VBA (and .NET) samples. For example, to add a header, the VBA examples shows:

  With ActiveDocument.Sections(1)
    .Headers(wdHeaderFooterPrimary).Range.Text = "Header text";
  End With


Which I translate to:

  WideString t_value = L"Header text";
 
  // FWordDoc is the ActiveDocument 
 
  FWordDoc.OlePropertyGet("Sections", 1).
    OlePropertyGet("Headers", wdHeaderFooterPrimary).
    OlePropertyGet("Range").
    OlePropertySet("Text", t_value);


This yielded runtime error: "'Item' is not a property"

The MSDN documentation has been no help.

Yes, it is. You just have to understand where to look and how to read it.
The information is there.

Because you have been helping me with C++ programming since 1998, I believe you.

That reference is for Word's .NET interop objects for C#/VB.NET. You need
to look at the OLEAutomation/VBA reference instead, which defines objects
that C++ can access. Start here instead:

https://msdn.microsoft.com/en-us/library/office/fp179696.aspx
https://msdn.microsoft.com/en-us/library/ee861527.aspx

I do see that I can get more information through these links... thank you so much! I'll keep waling on it and come back when I have more specific questions.

Kathleen
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Documentation for OleFunction, OlePropertyGetetckeywords/propertynames? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 22, 2016 6:51 PM   in response to: Kathleen Beaumont in response to: Kathleen Beaumont
Kathleen wrote:

That's part of my difficulty. The syntax for using those wrappers does
not match the VBA (and .NET) samples.

You are comparing apples (C++) and oranges (C#/VB). Obviously, you will
have to translate from one language to another.

If you want to read a property, use OlePropertyGet() with the property name.

If you want to write to a property, use OlePropertySet() with the property
name and value.

If you want to call a method that does not return a value, use OleProcedure()
with the method name and parameter value(s).

If you want to call a method that does return a value, use OleFunction()
with the method name and parameter value(s).

It is that simple.

For example, to add a header, the VBA examples shows:

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = </div>
"Header text";
<div class="jive-quote">


Which I translate to:

// FWordDoc is the ActiveDocument
FWordDoc.OlePropertyGet("Sections", 1).OlePropertyGet("Headers", wdHeaderFooterPrimary).OlePropertyGet("Range").OlePropertySet("Text", </div>
WideString(L"Header text"));
<div class="jive-quote">


This yielded runtime error: "'Item' is not a property"

"Sections(1)" does not translate to this:

OlePropertyGet("Sections", 1)


It translates to this instead:

OlePropertyGet("Sections").OleFunction("Item", 1)


Pay closer attention to the documentation. The Document.Sections property
returns an object, which then provides access to the child Section objects:

https://msdn.microsoft.com/EN-US/library/ff838480.aspx
https://msdn.microsoft.com/EN-US/library/ff821915.aspx

--
Remy Lebeau (TeamB)
Kathleen Beaumont

Posts: 4
Registered: 12/1/01
Re: Documentation for OleFunction, OlePropertyGetetckeywords/propertynames? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 23, 2016 7:10 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Kathleen wrote:

That's part of my difficulty. The syntax for using those wrappers does
not match the VBA (and .NET) samples.

You are comparing apples (C++) and oranges (C#/VB). Obviously, you will
have to translate from one language to another.

I understand. And I can (generally) do that, but...

If you want to read a property, use OlePropertyGet() with the property name.

If you want to write to a property, use OlePropertySet() with the property
name and value.

If you want to call a method that does not return a value, use OleProcedure()
with the method name and parameter value(s).

If you want to call a method that does return a value, use OleFunction()
with the method name and parameter value(s).

It is that simple.

This has been my issue: I could not find the correct names for properties, methods and parameters. The links you have given me, plus your explanations, have made the difference. I should be able to figure out the rest of what I'm trying to accomplish from this. (Oh yes I should... we'll see...)

"Sections(1)" does not translate to this:

OlePropertyGet("Sections", 1)


It translates to this instead:

OlePropertyGet("Sections").OleFunction("Item", 1)


Pay closer attention to the documentation.

I will. And thank you for your patient help.

Kathleen
Gord Pollock

Posts: 34
Registered: 12/13/03
Re: Documentation for OleFunction, OlePropertyGetetckeywords/propertynames? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 11, 2016 4:18 PM   in response to: Kathleen Beaumont in response to: Kathleen Beaumont
Having recently gone through the pain of converting a project over to
unicode, I would say this: "WideString" is your friend. Especially when
using OlePropertySet. Whether your string is char, wchar_t, Unicode, or
whatever, WideString worked the best for me. I would have problems even
when putting the 'L' in front of a string.

eg. this should have changed the title of the active sheet in the
workbook to "Project".

Variant CurrentSheet = ExlApp.OlePropertyGet("ActiveSheet");
CurrentSheet.OlePropertySet("Name", L"Project");  // doesn't work


Instead it thinks it is a boolean or something and changes the title to
"TRUE".

However, this worked like a charm.
CurrentSheet.OlePropertySet("Name", WideString("Project")); // or put
the name of
// the
string in the
// brackets

Also used WideString for cell addresses when using "Range" in
OlePropertyGet.
Vladimir Ulchenko

Posts: 248
Registered: 1/12/00
Re: Documentation for OleFunction, OlePropertyGet etckeywords/propertynames? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 23, 2016 12:40 AM   in response to: Kathleen Beaumont in response to: Kathleen Beaumont
On Wed, 22 Jun 2016 17:49:21 -0700, Kathleen Beaumont <> wrote:

That's part of my difficulty. The syntax for using those wrappers does not match the VBA (and .NET) samples. For example, to add a header, the VBA examples shows:

perhaps instead of using olevariants directly you could try to utilize wrapper headers imported from corresponding ms office type libs

Because you have been helping me with C++ programming since 1998, I believe you.

Remy is deserving admiration for devoting himself to these newsgroups indeed

--
Vladimir Ulchenko aka vavan
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02