-
FastReport 现已支持二维码功能,并包含源代码
资源介绍
{
工作中遇到这样的需求,苦苦找不到相关的代码,找到一个还是收费的!:(
本着共享互惠的精神,本人简单实现了一个 FastReport 打印二维码的应用。
使用方法非常简单,将压缩包中的 frx2DBarcode 单元添加到引用即可在报表设计中看到 2D 条码对象,进行设计、打印。
目前仅实现了 QRCcode 的打印,抛砖引玉,相信增加 PDF417,DM 编码应该不会太难。
如果对源代码做了改进和修改欢迎 EMAIL 给我一份,学习一下!
邮件: JulyXDay@QQ.COM 谢谢支持!
}
{******************************************}
{ }
{ FastReport v4.0 }
{ 2DBarcode object }
{ }
{ Copyright (c) 2012 }
{ by LiKejian }
{ QQ 39839655 }
{ }
{******************************************}
unit frx2DBarcode;
interface
{$I frx.inc}
uses
Windows, Messages, SysUtils, Classes, Graphics, frxClass
{$IFDEF Delphi6}
, Variants
{$ENDIF};
type
TfrxBarcode2DObject = class(TComponent); // fake component
TfrxBarcode2DView = class(TfrxView)
private
FEccLevel: SmallInt;
FModule: SmallInt;
FVersion: SmallInt;
FText: String;
FExpression: String;
public
constructor Create(AOwner: TComponent); override;
procedure Draw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX, OffsetY: Extended); override;
class function GetDescription: String; override;
procedure GetData; override;
published
property Version: SmallInt read FVersion write FVersion default 0;
property EccLevel: SmallInt read FEccLevel write FEccLevel default 0;
property Module: SmallInt read FModule write FModule default 0;
property DataField;
property DataSet;
property DataSetName;
property Expression: String read FExpression write FExpression;
property Frame;
property Text: String read FText write FText;
end;
implementation
uses frx2DBarcodeRTTI, frxDsgnIntf, frxRes, frxUtils, uQRCode;
constructor TfrxBarcode2DView.Create(AOwner: TComponent);
begin
inherited;
end;
class function TfrxBarcode2DView.GetDescription: String;
begin
Result := '2D 条形码对象';
end;
procedure TfrxBarcode2DView.Draw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX,
OffsetY: Extended);
const
sFileName = 'QRCode.bmp';
var
oBmp: TBitmap;
begin
BeginDraw(Canvas, ScaleX, ScaleY, OffsetX, OffsetY);
//Create 2D Barcode
CreateQRCode(FText, FVersion, FEccLevel, FModule);
if FileExists(sFileName) then
begin
oBmp := TBitmap.Create;
oBmp.LoadFromFile(sFileName);
frxDrawGraphic(Canvas, Rect(FX, FY, FX1, FY1), oBmp, IsPrinting, False, False, 0);
FreeAndNil(oBmp);
end;
DrawFrame;
end;
procedure TfrxBarcode2DView.GetData;
begin
inherited;
if IsDataField then
FText := VarToStr(DataSet.Value[DataField])
else if FExpression <> '' then
FText := VarToStr(Report.Calc(FExpression));
end;
initialization
frxObjects.RegisterObject1(TfrxBarcode2DView, nil, '', '', 0, 23);
finalization
frxObjects.UnRegister(TfrxBarcode2DView);
end.