> ## 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.

# User defined properties

> User defined properties in the FlexiLayout language: declare typed variables in the External fields section to share hypothesis values between elements.

A **user-defined property** is a typed variable that belongs to an element. These properties are defined in the **External fields** section on the **Advanced** tab.

Use the following format:

```text theme={null}
Type1 Name1;
...
TypeN NameN;
```

where `Name` is the variable name and `Type` is its type.

When fields are created, they are initialized automatically. For example, numerical fields are initialized with zero values, and rectangles and regions are initialized with empty values.

## Field scope and access

Fields can be used in the element to which they belong and in any element located lower in the search tree. The value of a field can be changed only in the element to which it belongs. In other elements, it is available as read-only.

To access a field of an element, use the full name of the field in the format `ElementName.FieldName` (for example, `SearchElements.StaticText1.x`). Within an element, its field can be accessed by name: `x`. For a compound element, its subelements (at any level of nesting) can also access its fields by their short names.

The value of a complex expression that characterizes the hypothesis for an element can be computed and written into a property. This value can then be accessed from any element lower in the search tree, without computing it each time it is needed. This reduces the time required to match the FlexiLayout, removes the need to copy a large expression into each element, and makes the code more readable.

## Field naming restrictions

* Within an element, field names must be unique.
* The name of an element in a compound element must not match any field name in its subelements (at any level of nesting).
* The field names of a compound element must not match the names of any of its subelements.

## Example: speed up matching with a user-defined property

This example searches for two address components: a city (character string **City**) and a subway station (character string **Station**). The subway station is specified only if the city is Moscow. To speed up FlexiLayout matching, the example defines a `fromMoscow` property for the **City** element. This property is `true` if the **City** element is detected and has the value `"Moscow"`, and `false` in all other cases.

Code for the **City** element, in the **External fields** section:

```text theme={null}
logic fromMoscow;
```

In the **Advanced post-search relations** section:

```text theme={null}
if( not IsNull and Value.Find( "Moscow" ) >= 0 ) then fromMoscow = true;
else fromMoscow = false;
```

The **Station** element then uses this property to search for the station only if Moscow is detected as the **City** element.

Code for the **Station** element, in the **Advanced pre-search relations** section:

```text theme={null}
if not City.fromMoscow then dontfind;
```

<Warning>
  Because of these fields, elements of the same type are not treated as identical.

  Therefore, the following construction is prohibited:

  ```text theme={null}
  Let e = SearchElements.StaticText1;
  e = SearchElements.StaticText2; // element of the same type
  ```
</Warning>
