import { Callout } from "zudoku/ui/Callout";

# Barcode API (obsolete)

Codeunit `5523581` `bdev.Barcode API` was the entry point of the app before version 18.2. It has been replaced by [bdev.Barcode](barcode.mdx) and is obsolete since then.

```pascal
    ObsoleteState = Pending;
    ObsoleteReason = 'Replaced by "bdev.Barcode".';
    ObsoleteTag = '18.2';
```

<Callout type="caution" title="Do not write new code against this codeunit">
`ObsoleteState = Pending` means the codeunit still compiles, with a warning. It will be removed in a future major version, and so will the `bdev.Barcode Format` enum and the `bdev.Barcode Defintion` table it works with.
</Callout>

## What to use instead

| `bdev.Barcode API` | Replacement |
| --- | --- |
| `Encode(Codeunit, Text, Enum "bdev.Barcode Format")` and its four longer overloads with height, width, margin and `includeText` | `bdev.Barcode`.`Encode(Enum "bdev.Barcode Symbology", Text)` for the defaults, or `Encode(Record "bdev.Barcode Settings", Text)` where the appearance matters |
| `Encode(Codeunit, Text, Code[20])` and `Encode(Codeunit, Text, Record "bdev.Barcode Defintion")` | `bdev.Barcode`.`Encode(Record "bdev.Barcode Settings", Text)` |
| `Decode(Codeunit, var Text)` | `bdev.Barcode`.`Decode(Codeunit)`, which returns the value instead of writing it to a `var` parameter |
| `HideValidationDialog(Boolean)` | No replacement, and none needed - the new codeunit shows no dialog |
| `BarcodeFormatToBarcodeSymbology(Enum)` | Only useful while migrating, see below |

## Moving code over

Two things change beyond the codeunit name.

**The result is returned, not filled in.** The old methods took the `Temp Blob` as a `var` parameter, the new ones return it:

```pascal
    // before
    barcodeApi.Encode(image, item."No.", format::QR_CODE);

    // after
    image := barcode.Encode(Enum::"bdev.Barcode Symbology"::"QR Code", item."No.");
```

**Appearance moves into a record.** Height, width, margin and "print the value below the code" were parameters; they are fields of `bdev.Barcode Settings` now. A call that passed them becomes a settings record - stored, when the appearance is a setup decision, or initialized in memory when it is not.

**The format enum becomes a symbology enum.** `bdev.Barcode Format` is replaced by `bdev.Barcode Symbology`. While migrating, `BarcodeFormatToBarcodeSymbology` translates a stored format value into the new enum, so that data written by an older version can be read:

```pascal
    barcodeSettings."Barcode Symbology" := barcodeApi.BarcodeFormatToBarcodeSymbology(mySetup."Barcode Format");
```

Once your setup stores the symbology, drop the call - it is obsolete along with the rest of the codeunit.

## See also

- [365 business Barcode - Overview](readme.mdx)
- [Barcode](barcode.mdx)
