You are here: Start » Function Reference » All Functions » Conditional Processing » MergeDefault
This is Filter Equivalent. This function may be present in generated code, but should not be used in hand-written code.
Header: | STD.h |
---|---|
Namespace: | fil |
Module: | FoundationLite |
Copies an object from a conditional input to an non-conditional output, replacing Nil with a predefined default value.
Applications: Usually used to create a definite result for the special cases represented by the Nil value.
Syntax
void fil::MergeDefault ( const typename ftl::ToConditionalType<const Type&>::Type& inConditionalObject, const Type& inDefaultObject, Type& outObject )
Parameters
Name | Type | Default | Description | |
---|---|---|---|---|
![]() |
inConditionalObject | const typename ToConditionalType<const Type&>::Type& | Input conditional object | |
![]() |
inDefaultObject | const Type& | Object to be used if the conditional object is empty | |
![]() |
outObject | Type& | Value of the conditional object, if it exists, or the default otherwise |
Description
This function is related to Conditional<T>. It receives a conditional value and:
- if it is Nil, replaces it with a specified default value;
- otherwise, copies the input value to the output.
Hints
- Connect a conditional value to the inConditionalObject input.
- On the inDefaultObject input define a value that will be substituted for Nil on the inConditionalObject input.
- Also consider the coalescing operator (??) in Formula Blocks.
- Also consider using a Variant Step macrofilter with two variants: "Nil" and "default". This may be more elegant and also faster.
Examples
Here is a simple demonstration how this filter works, replacing Nil with 0:
![]() |
![]() |
inConditionalObject = 5 inDefaultObject = 0 |
outObject = 5 |
inConditionalObject = Nil inDefaultObject = 0 |
outObject = 0 |
MergeDefault filter can be used to replace a numeric display in HMI with a label indicating a reading error, such as "(unknown)" or "N/A". Here, we are reading some value from an XML node. If it cannot be parsed (e.g. because there is incorrect syntax), then a special text will be displayed instead.

Remarks
This filter is a counterpart of the IFERROR function from Microsoft Excel.
This filter can be replaced with the following formula:

See Also
- MakeConditional – Checks a condition and: if the condition is True, then it copies the input object to the output; otherwise returns Nil.
- MergeBranches – Chooses the first non-Nil object, or reports an error if there is no such object.
- MergeConditionals – Returns the first not-Nil input object.
- MergeIntoArray – Creates an array from all the non-Nil input elements.