# RDatamatrix for Delphi

Copyright J4L (http://www.java4less.com).

- Introduction
  - Formats
  - Encoding
  - Control Characters
  - References
- Installation
- Example
- Fields and methods of the component

## Introduction

RDatamatrixX is a Delphi component that will allow you to create Datamatrix (ECC200) barcodes for your windows applications. The component can be used with any Delphi version starting with Delphi 4 (also tested with the most recent Delphi XE5) by simply recompiling the source code.

Data Matrix is a two-dimensional (2D) matrix symbology which is made up of square modules arranged within a perimeter finder pattern. It can encode up to 3116 characters from the entire 256 byte ASCII character set. The symbol consists of data regions which contain square modules set out in a regular array. Large ECC 200 symbols contain several regions. Each data region is delimited by a finder pattern, and this is surrounded on all four sides by a quiet zone border (margin).

ECC 200 symbols have an even number of rows and an even number of columns. Most of the symbols are square with sizes from 10 x 10 to 144 x 144. Some symbols however are rectangular with sizes from 8 x 18 to 16 x 48. All ECC 200 symbols can be recognized by the upper right corner module being light (binary 0).

ECC200 is the newest version of data matrix and supports advanced encoding error checking and correction algorithms (reed-solomon). This algorithms allow the recognition of barcodes that are up to 60% damaged.

The barcode supports two optional mechanisms:

- The "Extended Channel Interpretation" (ECI) mechanism enables characters from other character sets (e.g. Arabic, Cyrillic ..) and other data interpretations or industry-specific requirements to be represented.
- The "Structured append" allows files of data to be represented as a secuence of up to 16 Data Matrix symbols. The original data or file can be reconstructed regardless of the order of the symbols.

RDataMatrix supports:

- All sizes and formats (from 10x10 till 144x144)
- Ascii, text , C40 and Base256 (for binary data) encoding.
- The "Extended Channel Interpretation and Structured append

## Formats

RDataMatrix supports all data matrix formats. The following table contains the size , the capacity and the correction error features of each format:

Size | Numeric Capacity | Alphanumeric capacity | Binary capacity | Max Correctable Error/Erasure
10 x 10 | 6 | 3 | 1 | 2
12 x 12 | 10 | 6 | 3 | 3
14 x 14 | 16 | 10 | 6 | 5/7
16 x 16 | 24 | 16 | 10 | 6/9
18 x 18 | 36 | 25 | 16 | 7/11
20 x 20 | 44 | 31 | 20 | 9/15
22 x 22 | 60 | 43 | 28 | 10/17
24 x 24 | 72 | 52 | 34 | 12/21
26 x 26 | 88 | 64 | 42 | 14/25
32 x 32 | 124 | 91 | 60 | 18/33
36 x 36 | 172 | 127 | 84 | 21/39
40 x 40 | 228 | 169 | 112 | 24/45
44 x 44 | 288 | 214 | 142 | 28/53
48 x 48 | 348 | 259 | 172 | 34/65
52 x 52 | 408 | 304 | 202 | 42/78
64 x 64 | 560 | 418 | 278 | 56/106
72 x 72 | 736 | 550 | 366 | 72/132
80 x 80 | 912 | 682 | 454 | 96/180
88 x 88 | 1152 | 862 | 574 | 112/212
96 x 96 | 1392 | 1042 | 694 | 136/260
104 x 104 | 1632 | 1222 | 814 | 168/318
120 x 120 | 2100 | 1573 | 1048 | 204/390
132 x 132 | 2608 | 1954 | 1302 | 248/472
144 x 144 | 3116 | 2335 | 1556 | 310/590
8 x 18 | 10 | 6 | 3 | 3
8 x 32 | 20 | 13 | 8 | 5
12 x 26 | 32 | 22 | 14 | 7/11
12 x 36 | 44 | 31 | 20 | 9/15
16 x 36 | 64 | 46 | 30 | 12/21
16 x 48 | 98 | 72 | 47 | 14/25

## Encoding

The data represented in the symbol can be compressed using one or several of the following algorithms:

- ASCII: it is used to encode data that mainly contains ascii characters (0-127). It encodes one alphanumeric or two numeric characters per byte.
- C40: it is used to encode data that mainly contains numeric and upper case characters. C40 encodes three alphanumeric data characters into two bytes.
- TEXT: it is used to encode data that mainly contains numeric and lowercase characters. TEXT encodes three alphanumeric data characters into two bytes.
- BASE256: it is used to encode 8 bit values.

All encoding system can be used to encode any data, but for example, encoding binary data with C40 generates much more overhead (longer symbol) than with BASE256.

## Control characters

RDataMatrix uses the character ~ to recognize some special characters in the input data. The following possibilities are available:

- ~X is used to represent character values from 0 to 26. Replace the X like in the following example ~@ = means character ascii 0, ~A= means character 1, ~B=means character 2, ~C=means character 3 ...
- ~1: represents the character FNC1. When FNC1 appears in the first position (or in the fifth position of the first symbol of a Structured Append), it will indicate that the data conforms to the UCC/EAN Application Identifier standard format.
- ~2: It is used to represent Structured Append. Structured Append is used to link information from several symbols in a secuence. The ~2 must be followed by 3 additional bytes. The first 4 bits of the first byte identify the position of the particular symbol in the secuence . The last 4 bits identify the total number of symbols in the secuence. The second and third bytes are used as a file identifier are can have a value between 1 and 254 (up to 254*254=64516 identifiers). See Data Matrix Specification for more information about this (ISO 16022).
- ~3: This character is only allowed in the first position of the symbol. It indicates that the data contains commands for the barcode reader.
- ~4: not allowed.
- ~5 and ~6: These characters are only allowed in the first position of the symbol. If ~5 is used the header [)> ascii30 ascii05 ascii29 will be transmitted by the barcode reader before the data in the symbol and the trailer ascii30 ascii04 will be transmitted after the data. If a ~6 is used , the header [)> ascii30 ascii05 ascii29 will be transmittedby the reader before the data and the trailer ascii30 ascii04 will be transmitted afterwards.
- ~7NNNNNN specifies the Extended Channel to be used, where NNNNNN is a value between and 000000 - 999999. For example: ~7000010 means Extended Channel 10 . Extended channel is used for using other character sets other than ascii. See Data Matrix Specification for more information about this (ISO 16022).
- ~dNNN represents the ascii character encoded by the 3 digits NNN. For exmaple, ~d065 represents the character 'A'.

## References

You can find more information about data matrix at:

- BarCode 1
- AIM International, Inc.
- ISO 16022

## Installation

There are 2 installation possibilities ActiveX version and Delphi source code.

In order to install the ActiveX version of the control:

1. select main menu -> component -> import activeX control
2. click on "Add...", select RBarcodeDX.ocx file
3. You will now see: TBarcode1DX, TDatamatriX, TDPF417X and TMaxicodeX in the "Classes" window.
4. click on "Install", install window will come up.
5. click "ok" to install
6. the controls will appear in the "ActiveX" tab of the components palette.

In order to install from the Delphi source code (registered users only):

1. select main menu -> component -> install component
2. click on "browse" and select Datamatrix.pas
3. click "ok"
4. the control will appear in the "Barcodes" tab of the components palette.

##

## Examples

In order to run the sample application you must execute datamatrixDemo.exe or barcode1D2DDemo.exe.

> ###

## Properties and methods

The TDatamatrix component is a subclass of TGraphicControl and can therefore be placed on any form or container. This is the esiest way to use it , however you can also create an instance of the component by program and then paint the barcode on any canvas object using the paintBarcode() method.

The component TDatamatrix has following properties and methods:

> ### Methods

> - paintBarcode(canvas): pains the barcode on the provided canvas.

> ### Properties

> - processTilde: process the " ~ " in the string to be encoded.
> - BackColor: background color.
> - BarColor: foreground color (color of the pixels).
> - CalculatedFormat. Format actually used for the barcode. It can be the preferredFormat or a larger one if the data does not fit in the requested one.
> - code: string to be encoded.
> - rebuild: set it to true if you need to rebuild the barcode. It is automatically set to false after the barcode is painted.
> - encoding: encoding to be used:
>   - Ascii encoding
>   - C40 encoding
>   - Text encoding
>   - Base256 encoding
>   - None
>   - Automatic
> - preferredFormat: format to be used:
>   - AUTO
>   - C10X10
>   - C12X12
>   - C14X14
>   - C16X16
>   - C18X18
>   - C20X20
>   - C22X22
>   - C24X24
>   - C26X26
>   - C32X32
>   - C36X36
>   - C40X40
>   - C44X44
>   - C48X48
>   - C52X52
>   - C64X64
>   - C72X72
>   - C80X80
>   - C88X88
>   - C96X96
>   - C104X104
>   - C120X120
>   - C132X132
>   - C144X144
>   - C8X18
>   - C8X32
>   - C12X26
>   - C12X36
>   - C16X36
>   - C16X48
> - CurrentX (readonly): real size of the barcode. The value is set after the barcode is painted. Can be use to create an image of the exact size.
> - CurrentY (readonly): real size of the barcode. Can be use to create an image of the exact size.
> - Margin: top margin in pixels (default is 30).
> - PixelsDot: size of the dots (in pixels) of the matrix.

You can also use the component in order to paint onto an external canvas. For example, in order to create a bitmap file you would use the following code:

> var
> bmp: TBitmap;
> begin
> bmp:=TBitmap.create();
> bmp.height:=200;
> bmp.width:=200;
> {use paintBarcode() to paint onto an external Canvas}
> barcode.paintBarcode(bmp.Canvas);

> bmp.saveToFile('barcode.bmp');
> end;