Printing bar codes in QuickReports

Any database field can be printed automatically as any type of bar code, anywhere in your reports.

Before you use these instructions you should first design your QuickReport.

Test your quick report is printing the correct values, before you begin to use bar codes.

Using the OnPrint event

You can make QuickReport objects (i.e. QRDBText, QRLabel, QRDBCalc) print as bar codes automatically.

- In your QuickReport, select the object you want to print as a bar code.

If you choose a QRLabel object you can print a fixed bar code. If you choose a QRDBText or QRDBCalc object, you can print database fields or calculated values as bar codes, automatically.

- Choose menu View | Object Inspector. In the Object Inspector select the Events tab.

- In the OnPrint event, enter a procedure name. For example, enter PrintAsBarcode.

- Press enter to view the event code;

{$INCLUDE CIAXCOM.PAS}

procedure TForm1.PrintAsBarcode(sender: TObject; var Value: String);

begin

end;

- Edit the code to look like the code below.

{$INCLUDE CIAXCOM.PAS}

procedure TForm1.PrintAsBarcode(sender: TObject; var Value: String);

begin

Value := Barcode(PAnsiChar(Value), 'BarCodeType', DisplayErrors);

end;

Replace BarCodeType with the type of bar code you want. See Specifying a bar code type for more details. For example, to produce a Code 128 bar codes use C128-0.BA.

Replace DisplayErrors with 1 to display any error messages in a message box. Use 0 to disable error messages.

Example: To print the object as a Code 128 bar code;

{$INCLUDE CIAXCOM.PAS}

procedure TForm1.PrintAsBarcode(sender: TObject; var Value: String);

begin

Value := Barcode(PAnsiChar(Value), 'C128-0.BA', 1);

end;

Selecting a bar code font

- In your QuickReport, select the object you want to print as a bar code.

- In the Object Inspector, set the Font property. Set the Name and Size properties to the bar code font name and size you want to use. See Bar code font name and font size to use for more details. For example, to print Code 128 bar codes use font name CIA Code 128 Medium and font size 14.

Set AutoSize property to True.


Copyright 2000 CIA (BAR CODES) UK. All rights reserved. Reproduction prohibited.