Read-only properties in raw C++

Certain ABBYY FineReader Engine objects (for example, ILayout::Blocks) have read-only object properties. Such properties cannot be changed directly in raw C++. If you want to change one of these properties, you need to 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 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);

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Recently viewed