Skip to content

TTMSFNCWXBarcode

The TTMSFNCWXBarcode is a component to generate barcodes. It uses the bwip-js JavaScript library.

There are various supported barcode formats. To familiarize yourself with the supported formats and the settings that applies to them, please visit the documentation page of the original bwipp library: https://github.com/bwipp/postscriptbarcode/wik

Creating barcodes

To create a barcode, all you need to do is set the TTMSFNCWXBarcode.BarcodeType and TTMSFNCWXBarcode.Text properties. This can be done both at designtime and runtime. Giving an unsupported format as Text or selecting a BarcodeType that does not support the current Text will cause an exception.

procedure TForm1.Button1Click(Sender: TObject);
begin
 try
 TMSFNCWXBarcode1.BarcodeType := bciCode93Ext;
 except
 //handle exception here
 end;
 try
 TMSFNCWXBarcode1.Text := 'My code';
 except
 //handle exception here
 end;
end;

Retrieving barcodes

To retrieve the barcodes, implement the TTMSFNCWXBarcode.OnGetBarcode event. Access to the generated barcode is provided as a TTMSFNCBitmap. Process the TTMSFNCBitmap parameter as it fits best:

procedure TForm1.TMSFNCWXBarcode1GetBarcode(Sender: TObject;
 ABitmap: TTMSFNCBitmap);
begin
 //Save into a file, for example:
 ABitmap.SaveToFile('path_to\my_code.png');
end;
To retrieve a barcode syncronously, use the TMSFNCWXBarcode.GetBarcode(AText: string) method. Keep in mind, this method won’t work on Android platforms.
procedure TForm1.Button1Click(Sender: TObject);
var
 bmp: TTMSFNCBitmap;
begin
 //Save into a file, for example:
 bmp := TMSFNCWXBarcode1.GetBarcode('codetocreate');
 try
 bmp.SaveToFile('path_to\my_code.png');
 finally
 bmp.Free;
 end;
end;

Customization

It’s possible to customize the barcode with type specific settings though the provided TMSFNCWXBarcode.Settings property. To customize the look of the barcode, use the TTMSFNCWXBarcode.BarcodeBorder, TTMSFNCWXBarcode.Scale and TTMSFNCWXBarcode.Color properties.

procedure TForm1.Button1Click(Sender: TObject);
begin
 TMSFNCWXBarcode1.BarcodeBorder.Color := gcRed;
 TMSFNCWXBarcode1.BarcodeBorder.Width := 2;
 TMSFNCWXBarcode1.BarcodeBorder.Visible := True;
 TMSFNCWXBarcode1.Color := gcAliceblue;
 TMSFNCWXBarcode1.Scale := 2; //Make it bigger while maintaining correct 
line ratio
end;

TTMSFNCWXBarcode