> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Working with Properties

The interfaces of ABBYY FlexiCapture SDK objects have various properties and methods. As Visual Basic users are familiar with the notion of property, we will discuss the way the properties are handled in C++.

For a C++ user, a property is a couple of methods (get and put for read-write properties) or a single get method (for read-only properties). However, the "Native COM support" featured by Microsoft Visual C++ makes the way the properties are handled more like the one used in Visual Basic. This is the way implied by the sense on the noun "property."

The ABBYY FlexiCapture SDK properties may be of the following types:

| **IDL** | **Visual Basic type** | **C++ type** | **C#** |
| - | - | - | - |
| **VARIANT\_BOOL** (**VARIANT\_TRUE** or **VARIANT\_FALSE**) | Boolean (with two values, True and False) | VARIANT\_BOOL (with two values VARIANT\_TRUE and VARIANT\_FALSE) | bool (true or false) |
| **int** | Integer | int | int |
| **double** | Double | double | int |
| **BSTR**, a pointer to Unicode string. Zero value specifies an empty string. | String | BSTR, a pointer to Unicode string. Zero value specifies an empty string. | string |
| **\_\_int64** | Int64 | \_\_int64 | Int64 |
| **HANDLE\*** | | | |
| **IUnknown-derived interface** | Object | IUnknown-derived interface | object |
| **enum** | Enumeration | Enumeration | enum |

See the details of working with different types of properties below:

> [accordion] Working with simple properties
>
> We will use the Boolean property to describe how simple properties are used. This property is described in the type library as follows:
>
> ```cpp theme={null}
> interface IMyObject : IUnknown {
> ...
> [propget]
> HRESULT MyProperty([out, retval]VARIANT_BOOL* pVal);
> [propput]
> HRESULT MyProperty([in]VARIANT_BOOL newVal);
> ...
> };
> ```
>
> A Visual Basic user handles this property as follows:
>
> ```vb theme={null}
> If MyObject.MyProperty <> True Then
>    MyObject.MyProperty = True
> End If
> ```
>
> A C++ user, on the other hand, uses two methods to work with this property. These methods have get\_ and put\_ prefixes. The respective C++ code should look as follows:
>
> ```cpp theme={null}
> IMyObject* pMyObject;
> ...
> VARIANT_BOOL res;
> pMyObject->get_MyProperty(&res);
> if( res != VARIANT_TRUE )
>    pMyObject->put_MyProperty(VARIANT_TRUE);
> ```
>
> However, the Native COM support makes the procedure simpler, and the respective code should look like this:
>
> ```cpp theme={null}
> IMyObjectPtr pMyObject;
> ...
> if(pMyObject->MyProperty != VARIANT_TRUE)
>    pMyObject->MyProperty = VARIANT_TRUE
> ```
>
> If the type library only defines the "get" method for a property, this property is called read-only. Its value cannot be changed by the user, it may only be accessed for "reading."

> [accordion] Working with string properties
>
> Working with string properties is very similar to working with simple properties, but has its own specifics. A C++ user working with string properties must free the strings that are passed to set-methods, and also those that are returned by get-methods. However, this is done automatically in Visual Basic and in C++ with the Native COM support. Suppose **MyObject** also supports a string property called **Name**. This property is described in the type library as follows:
>
> ```cpp theme={null}
> interface IMyObject : IUnknown {
> ...
> [propget]
> HRESULT Name([out, retval]BSTR* pVal);
> [propput]
> HRESULT Name([in]BSTR newVal);
> ...
> };
> ```
>
> A C++ user works with this property like this:
>
> ```cpp theme={null}
> IMyObject* pMyObject;
> ...
> // "get" method
> BSTR res;
> pMyObject->get_Name(&res);
> ...
> // Now free the string allocated in ABBYY FlexiCapture SDK
> ::SysFreeString(res);
> // "put" method
> BSTR str = ::SysAllocString(L"New Name");
> pMyObject->put_Name(str);
> // Now free the string that we allocated
> ::SysFreeString(str);
> ```
>
> For Visual Basic this may be rewritten:
>
> ```vb theme={null}
> Dim obj As MyObject
> Dim res As String
> res = obj.Name
> Dim str As String
> str = "New Name"
> obj.Name = str
> ```

> [accordion] Working with object properties
>
> A C++ user will say that the parameters of "get" methods of "Object" properties are pointers to an object's interface pointer. As the interfaces of the objects are derived from IUnknown, they may be passed as IUnknown pointers to the properties or methods, which use objects of several types as input or output parameters (you may, however, get the interface you need by calling the QueryInterface method).
>
> There are two different types of "put" methods for object properties — clear put, described by the **propput** keyword in the type library (the object is copied in this case); and put by reference, described by the **propputref** keyword in the type library (only a pointer to an existing object's interface is stored in the property in this case). A property may support only one of these put methods; most of ABBYY FlexiCapture SDK object properties clear put. In Visual Basic put by reference is performed using the Set statement, while clear put is performed without this keyword.
>
> Suppose again the **MyObject** object supports **MyObjectProperty** property that refers to an object of **MyChildObject** type.
>
> ```cpp theme={null}
> interface IMyObject : IUnknown {
> ...
> [propget]
> HRESULT MyObjectProperty([out, retval]IMyChildObject** pVal);
> [propputref]
> HRESULT MyObjectProperty([in]IMyChildObject* newVal);
> ...
> };
> ```
>
> The same property is accessed as follows in Visual Basic:
>
> ```vb theme={null}
> Dim ChildObj As MyChildObject
> Set ChildObj=MyObject.MyObjectProperty
> ' Do something with the object
> ...
> ' Clear put (If it were put by reference, we would write
> ' Set MyObject.MyObjectProperty=ChildObj)
> MyObject.MyObjectProperty=ChildObj
> ```
>
> A C++ user will write this code as follows:
>
> ```cpp theme={null}
> IMyObject* pMyObject;
> ...
> IMyChildObject* pChildObj=0;
> // get_ method may return 0 in certain cases
> pMyObject->get_MyObjectProperty(&pChildObj);
> // Do something with the object
> ...
> pMyObject->put_MyObjectProperty(pChildObj);
> ...
> pChildObj->Release();
> ```
>
> Note that in C++ you should call the **Release** method for an object got via a property. The Native COM support calls **AddRef** and **Release** methods automatically using auto pointers.
>
> > [!WARNING]
> >
> > If an object property refers to a child object of the object that exposes this property, a pointer to the child object's interface is valid until its parent object exists. An attempt to access a child object after its parent object is destroyed may result in an error.

## Working with read-only object properties

Certain ABBYY FlexiCapture SDK objects have read-only object properties. This does not mean that such properties cannot be changed, this only means that they cannot be changed directly. In raw C++, if you want to change such a property, you need to pass a reference to the property object to a new variable, and then use this variable to change it. Below you can see a C++ sample for the [**IProject::Batches**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/project.md#batches) property which is represented by a read-only collection:

```cpp theme={null}
IProject* pProject = 0;
IBatches* pBatches = 0;
IBatch* pBatch = 0;
...
// The pBatches variable receives a reference to the batches collection from the Project
pProject->get_Batches( &pBatches );
// Add one more element to the batches collection
pBatches->AddNew( L"BatchName", &pBatch );
...
```

## See also

[Types of ABBYY FlexiCapture SDK Properties](https://docs.abbyy.com/flexi-capture/sdk/api-reference/propertiestypes.md)
