📄 ppbarcod.pas
字号:
{ RRRRRR ReportBuilder Class Library BBBBB
RR RR BB BB
RRRRRR Digital Metaphors Corporation BB BB
RR RR BB BB
RR RR Copyright (c) 1996-2001 BBBBB }
unit ppBarCod;
interface
{$I ppIfDef.pas}
uses
{$IFDEF Delphi6}Variants,{$ENDIF}
Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms, Dialogs, Menus,
ppClass, ppCtrls, ppTypes, ppUtils, ppDevice, ppDrwCmd, ppDB, ppPrnabl, ppComm,
ppDsgnCt, ppRTTI;
type
EBarCodeError = class(Exception);
{@TppCustomBarCode
Ancestor from which all barcode components descend. The standard barcode components
provided with ReportBuilder are:
- TppBarCode
- TppDBBarCode}
{@TppCustomBarCode.AddOnCode
The AddOnCode property allows you to implement either 2 or 5 digit addon
codes for UPC or EAN. If you try to enter an AddOnCode and the BarCodeType
property is not set to either bcUPC_A or bcEAN_13, an exception will be
raised. The AddOnCode is used for a few rather specific purposes. The 2
digit addon code is used to track the serial number of periodicals, mainly
magazines. The 5 digit addon has several purposes, but mainly it is used in
conjunction with EAN-13 for bar coding books. A books ISBN number can be
encoded in the actual EAN code. Then the addon code is used to indicate the
price of the book and the currency. This form of EAN is commonly known as
"Bookland EAN."}
{@TppCustomBarCode.AutoEncode
This property is used in conjunction with the Code 128 symbology. Code 128
can be difficult to work with because there are actually three code sets
within it, each used for a different purpose. Added to this complexity is
the capability to switch between code sets within the same symbol. You can
even switch to another code set for a single character only.
The AutoEncode property alleviates the difficulty of implementing Code 128
symbols. You no longer need to be concerned with any of the special control
codes for set switching. Instead, set AutoEncode to True to invoke a
proprietary algorithm which will automatically encode data as efficiently as
possible. You simply set the Data property to the actual data you want to
encode and the BarCode component will generate the most compact code
possible.
Note: For Code 128 symbols, AutoEncode defaults to True. (e.g. when you
select bcCode128 as the BarCodeType, AutoEncode will be set to True). You
should only set this property to False if you have some special requirement
and need to encode the symbol yourself.}
{@TppCustomBarCode.AutoSizeFont
By default, the human readable text is set to a standard accepted font size
based on the size of the barcode component. In order to take manual control
of the font size, set AutoSizeFont to False. The human readable text will
then be sized based on the value of the Font.Size property.}
{@TppCustomBarCode.BarCodeType
This is the main property of the component. It defines which symbology you
want to use to create the bar code. When you set the BarCodeType, the Data
property will be checked to ensure that the data is acceptable for the
chosen type. For example, you cannot have alpha characters in an Interleaved
2 of 5 code. If the data is not acceptable, an exception will be raised.
These are the possible values:
<Table>
Value Meaning
-------------------
bcCodabar the bar code is created using Codabar.
bcCode128 the bar code is created using Code 128.
bcCode39 the bar code is created using Code 39.
bcEAN_8 the bar code is created using EAN-8.
bcEAN_13 the bar code is created using EAN-13.
bcInt2of5 the bar code is created using Interleaved 2 of 5.
bcPostnet the bar code is created using PostNet.
bcUPC_A the bar code is created using UPC-A.
bcUPC_E the bar code is created using UPC-E.
</Table>}
{@TppCustomBarCode.BarColor
Use this property to set a color for the actual bars themselves as well as
the human readable text beneath the bar code.
Note: for best scanning, bar codes should be black bars on a white
background.}
{@TppCustomBarCode.BarWidth
This property allows you to change the width of each bar. For barcodes that
have a narrow to wide bar ratio, the wide BarWidth is calculated based on
the WideBarRatio property. If you have the AutoSize property set to True,
the component will resize when this property is changed.
The standard accepted BarWidth for each symbology is listed below.
<Table>
Type Inches Millimeters Comment
----------- --------------- --------------- -------
Code 128 0.0070 to 0.015 0.1778 to 0.381 Varies based on use.
Code 39 0.010 0.254
EAN-13 0.013 0.3302
Int. 2 of 5 0.015 0.381
Postnet 0.020 0.508
We strongly
recommend using
this value for
Postnet.
UPC-A 0.013 0.3302
</Table>
Note: These are only recommendations, you are free to use whatever BarWidth
you choose.
Further Note: We have successfully printed a Code 128 barcode on a 300 dpi
laser printer with a bar width of 0.0070 inches. That is an extremely
efficient code!}
{@TppCustomBarCode.BearerBars
Bearer bars are horizontal lines that run along the top and bottom of the
code. When bearer bars are not present, a partial scan can sometimes be
interpreted as a complete scan. Bearer bars greatly reduce the chance of
this happening.
Note: Only Interleaved 2 of 5 bar codes can have bearer bars. The other
symbologies do not need them. If you try to set BearerBars equal to True for
any other symbology, an exception will be raised.}
{@TppCustomBarCode.CalcCheckDigit
When this property is to True, a check digit is automatically generated for
UPC-A and EAN-13 barcodes. If CalcCheckDigit is set to False, then you must
provide all 12 digits of the UPC code in the Data property, or an exception
will be raised.}
{@TppCustomBarCode.Color
The background color for the component. Defaults to white.
Note: for best scanning, bar codes should be black bars on a white
background.}
{@TppCustomBarCode.Data
Use this property to specify the data to be encoded. Data for each bar code
symbology must follow certain rules or an exception will be raised. A
description of acceptable data for each type of barcode is provided in the
TppBarCode help topic.
Note: Code 128 requires special characters in order to function properly.}
{@TppCustomBarCode.Font
This is the font that will be used to draw the human readable portion of the
barcode. Also note that you can change the font attributes (bold, italic,
etc.), but the font's size, by default, is automatically calculated by the
component. If you wish to specify a font size yourself, you must set the
AutoSizeFont property to False. The Font's color is taken from the BarColor
property, as all barcode specifications call for the bars and human readable
text to be the same color.
If possible, you should always use the font OCR-B font for the human
readable portion of your barcode. If you do not have this TrueType font, it
is available from a variety of sources. Most bar code specification
documents call for this font to be used.
Note: Always assign a scalable font (either TrueType or ATM) to a barcode
component, otherwise text rotation and other font related functionality may
not work properly.}
{@TppCustomBarCode.Orientation
The Orientation property is used to rotate the bar code in 90 degree
increments. You would never want to have a bar code that is not rotated in
an increment of 90 degrees. The human readable text is also rotated. These
are the possible values:
<Table>
Value Meaning
---------------------------
orLeftToRight The bar code is created from Left to Right (this is the
default.)
orRightToLeft The bar code is created from Right to Left.
orTopToBottom The bar code is created from Top to Bottom.
orBottomToTop The bar code is created from Bottom to Top.
</Table>}
{@TppCustomBarCode.PrintHumanReadable
This property allows you to set whether the component will output the human
readable version of the bar code (i.e. the actual letters or numbers). Bar
codes like UPC-A and EAN-13 should always have this set to True. As for the
other bar codes, it is completely up to you.}
{@TppCustomBarCode.Visible
The Visible property determines whether a report component will be printed.
You can conditionally print a report component by setting the Visible
property at run-time from an OnPrint event handler.
You can suppress the printing of an entire band by setting the Visible
property of each report component to False. If the PrintHeight property of
the report band is set to phStatic, then blank white space equivalent to the
height of the band will be printed. If PrintHeight is set to phDynamic, no
page space is used and the next band begins printing. If you want to
suppress an entire band, it is usually best to use the Visible property of
the band itself.
To set the Visible property from the Report Designer, position your mouse
cursor over the component and click the right mouse button. The Visible
option should be near the bottom of the speedmenu. If it is checked, the
component will be printed. Selecting the Visible option from this menu will
toggle its value.}
{@TppCustomBarCode.WideBarRatio
This property effects the narrow-to-wide bar ratio for symbologies that have
such elements. The value you give this property will be multiplied by the
value of BarWidth to get the wide bar width. Most symbologies dictate a
wide bar ratio in the 2.0 to 3.0 range. You will want a higher WideBarRatio
if your BarWidth is very small. Most applications call for this ratio to be
3.0.}
TppCustomBarCode = class(TppCustomComponent)
private
FAddOnCode: String;
FAutoEncode: boolean;
FAutoSizeFont: Boolean;
FAutoWidth: Longint;
FAutoHeight: Longint;
FBarCodeType: TppBarCodeType;
FBarColor: TColor;
FBarWidth: Longint;
FBearerBars: Boolean;
FCalcCheckDigit: Boolean;
FData: String;
FDrawCommand: TppDrawBarCode;
FOrientation: TppBarCodeOrientation;
FBarCodeImage: TBitmap;
FPrintHumanReadable: Boolean;
FWideBarRatio: Longint;
FUpdating: Integer;
FCodeOk: Boolean;
FPainting: Boolean;
procedure BarCodeChangeEvent(Sender: TObject);
procedure CalcSize(aDeviceClass: TppDeviceClass);
function IsValidData(aData: String): Boolean;
function GetBarWidth: Single;
function GetWideBarRatio: Single;
procedure SetAddOnCode(Value: string);
procedure SetAutoEncode(Value : boolean);
procedure SetAutoSizeFont(Value: Boolean);
procedure SetBarColor(Value: TColor);
procedure SetBarWidth(Value: Single);
procedure SetBearerBars(Value: Boolean);
procedure SetCalcCheckDigit(Value: Boolean);
procedure SetData(Value: string);
procedure SetOrientation(Value: TppBarCodeOrientation);
procedure SetPrintHumanReadable(Value: Boolean);
procedure SetWideBarRatio(Value: Single);
{read/write private properties}
procedure ReadBarWidth(Reader: TReader);
procedure WriteBarWidth(Writer: TWriter);
procedure ReadWideBarRatio(Reader: TReader);
procedure WriteWideBarRatio(Writer: TWriter);
protected
{override from TComponent}
procedure DefineProperties(Filer: TFiler); override;
procedure AdjustBounds; override;
procedure BoundsChange; override;
function CanOptimizeDesignPainting: Boolean; override;
procedure CreatePopupMenu(aOwner: TComponent; var aPopupMenu: TppPopupMenu); override;
procedure DisplayMessage(aMessage: String); virtual;
procedure DrawBarCode;
procedure FontChanged(Sender: TObject); override;
function GetCaption: String; override;
function GetData: String; virtual;
function GetDefaultData: string;
function GetDefaultPropHint: String; override;
procedure PropertiesToDrawCommand(aDrawCommand: TppDrawCommand); override;
procedure SetAutoSize(Value: Boolean); override;
procedure SetBarCodeType(Value: TppBarCodeType); virtual;
procedure SetCaption(Value: String); override;
procedure SetFont(Value: TFont); override;
{popup menu event handlers}
procedure ConfigureMenuClick(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure BeginUpdate;
procedure EndUpdate;
procedure PaintDesignControl(aCanvas: TCanvas); override;
procedure PopupMenuClick(Sender: TObject); override;
procedure GetBarCodeImage(aCanvas: TCanvas);
property AddOnCode: string read FAddOnCode write SetAddOnCode;
property AutoEncode: boolean read FAutoEncode write SetAutoEncode default False;
property AutoSizeFont: Boolean read FAutoSizeFont write SetAutoSizeFont default True;
property BarCodeType: TppBarCodeType read FBarCodeType write SetBarCodeType;
property BarColor: TColor read FBarColor write SetBarColor;
property BarWidth: Single read GetBarWidth write SetBarWidth stored False;
property BearerBars: Boolean read FBearerBars write SetBearerBars default False;
property CalcCheckDigit: Boolean read FCalcCheckDigit write SetCalcCheckDigit default True;
property Data: string read GetData write SetData;
property Orientation: TppBarCodeOrientation read FOrientation write SetOrientation default orLeftToRight;
property PrintHumanReadable: Boolean read FPrintHumanReadable write SetPrintHumanReadable default True;
property WideBarRatio: Single read GetWideBarRatio write SetWideBarRatio;
property Color;
property Font;
property Visible;
end; {class, TppCustomBarCode}
{@TppBarCode
A bar code is a series of lines and spaces which represent data. A
special set of rules is used to convert data into the lines and spaces
of a barcode. This set of rules is called a symbology. There are many
different symbologies, some for general purpose use and some for very
specific applications. With TppBarCode, you can create valid bar codes
for the most popular symbologies. They are:
* Codabar
* Code 128
* Code 39
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -