# AddCustomBinder
{: .no_toc }

Registers a user-supplied binder that resolves symbols dynamically at compile time.

Syntax: *service*.**AddCustomBinder** *customBinder*

*service*
: *required* An object expression that evaluates to a **TbExpressionService** object.

*customBinder*
: *required* An object that implements [**ITbCustomBinder**](/tB/Modules/TbExpressionService/index.md#itbcustombinder-interface).

Use **AddCustomBinder** when [**AddCustomBinderObject**](/tB/Modules/TbExpressionService/AddCustomBinderObject.md) doesn't fit --- for example, when the names available to the expression are not statically known, when a name should resolve to something other than a member access on a fixed object, or when the implementer needs to inspect the argument count at the call site as part of resolution.

The engine calls [**Bind**](/tB/Modules/TbExpressionService/Bind.md) on each registered custom binder during compilation, once per unresolved symbol. The first binder that returns a non-**Nothing** result wins. Multiple custom binders can be registered with one service, and they are consulted in registration order.

> [!WARNING] BETA 1045
> A *customBinder* of **Nothing** ends the program with an access violation, in a 32-bit and a 64-bit build alike.

### Example

This example registers a class instance as both a property source (via [**AddCustomBinderObject**](/tB/Modules/TbExpressionService/AddCustomBinderObject.md) with [**IsAppObject**](/tB/Modules/TbExpressionService/index.md#IsAppObject)) and a custom binder. Bare symbols in the expression are first looked up as members of `Me` via the property source; whatever isn't matched there falls through to `Me.Bind`, which can resolve it dynamically --- for example, against a live recordset.

```tb check_build
' Inside a class that does: Implements ITbCustomBinder
Dim Service As TbExpressionService = New TbExpressionService
Service.AddStdLibraryBinder()
Service.AddCustomBinderObject "Report", Me, IsAppObject
Service.AddCustomBinder Me

Dim Expr As ITbExpression = Service.Compile("UCase(FieldName) & "" — "" & Title")
```

### See Also

- [Bind](/tB/Modules/TbExpressionService/Bind.md) method
- [Compile](/tB/Modules/TbExpressionService/Compile.md) method
- [AddStdLibraryBinder](/tB/Modules/TbExpressionService/AddStdLibraryBinder.md) method
- [AddCustomBinderObject](/tB/Modules/TbExpressionService/AddCustomBinderObject.md) method
