How to work with read-only properties in raw C++

Question

How to work with read-only properties in raw C++?

Answer

Certain FineReader Engine objects (for example, ILayout::Blocks) have read-only object properties. Such properties cannot be changed directly in raw C++. If there is a need to change one of these properties, please pass a reference to the property object to a new variable, and then use this variable to change it.

C++ sample for the ILayout::Blocks property, which is represented by a read-only collection:

ILayout* pLayout = 0;
ILayoutBlocks* pLayoutBlocks = 0;
long blockIndex;
...
// The pLayoutBlocks variable receives a reference to the block collection from Layout
pLayout->get_Blocks( &pLayoutBlocks );
// Remove an element from the blocks collection, e.q. modify read-only property
pLayoutBlocks->Remove( blockIndex );

Sometimes such properties allow modification using put_ property. To modify such a property one needs to create a new empty object, copy all values from an existing object with CopyFrom method, modify the new object's properties, then assign it back with put_ property.

ILayout* pLayout = 0;
ILayoutBlocks* pLayoutBlocks = 0;
long blockIndex;
IBlock pBlock;
IRegion newBlockRegion;
...
// The pLayoutBlocks variable receives a reference to the block collection from Layout
pLayout->get_Blocks( &pLayoutBlocks );
pLayoutBlocks->get_Element(i, &pBlock);
Engine->CreateRegion(&newBlockRegion);
... // assign a valid region
pBlock->put_Region(newBlockRegion);

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.

Recently viewed