unit AztecCodeDemo;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls,AztecCode,printers, ComCtrls;

type
  TAztecDemo = class(TForm)
    Image1: TImage;
    btnRefresh: TButton;
    btnExit: TButton;
    btnPrint: TButton;
    Button1: TButton;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label10: TLabel;
    Label18: TLabel;
    txtindex: TEdit;
    txtFileId: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Margin: TLabel;
    Label5: TLabel;
    txtCode: TEdit;
    cEncoding: TComboBox;
    cFormat: TComboBox;
    txtSize: TEdit;
    txtMargin: TEdit;
    txtPrinterSize: TEdit;
    txtEC: TEdit;
    Label6: TLabel;
    txtTotal: TEdit;
    Label7: TLabel;
    chkStructuredAppend: TCheckBox;
    Label8: TLabel;
    cType: TComboBox;
    Label9: TLabel;
    txtRune: TEdit;
    procedure btnExitClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
    procedure btnRefreshClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    aztec:TAztecCode;
  public
    { Public declarations }
  end;

var
  AztecDemo: TAztecDemo;

implementation

{$R *.DFM}

procedure TAztecDemo.btnExitClick(Sender: TObject);
begin
hide();
end;

procedure TAztecDemo.Button1Click(Sender: TObject);
var
bmp:TBitmap;
begin
       bmp:=TBitmap.create();
     bmp.height:=400;
     bmp.width:=400;
     aztec.paintBarcode(bmp.Canvas);
     bmp.SaveToFile('aztec.bmp');

     MessageDlg('Image saved to aztec.bmp.', mtInformation,      [mbOk], 0);

end;

procedure TAztecDemo.btnPrintClick(Sender: TObject);
var
value:integer;
dummy:integer;
begin
     with printer do
     begin
		BeginDoc;

                {dots size}
                val(txtPrinterSize.text,value,dummy);
                aztec.moduleSize:=value;

                aztec.offsetX:=printer.PageWidth div 10;
		aztec.paintBarcode(Canvas);

		EndDoc;
     end;
end;


procedure TAztecDemo.btnRefreshClick(Sender: TObject);
var
dummy:integer;
value:integer;
begin


{create new barcode}
{encoding}
if (cEncoding.itemIndex<>1) then aztec.encoding:=NORMAL
else aztec.encoding:=BINARY;
{value}
aztec.code:=txtCode.text;
aztec.processTilde:=true;
{format}
if (cFormat.itemIndex>=0) then aztec.PreferredConfiguration:=TAztecConfiguration(cFormat.itemIndex+1)
else aztec.PreferredConfiguration:=CONFIGURATION_15X15_COMPACT;
{type}
if (cType.itemIndex>=0) then aztec.ConfigurationType:=TAztecConfigurationType(cType.itemIndex)
else aztec.ConfigurationType:=CONFIGURATION_ANY;

{dots size}
val(txtSize.text,value,dummy);
aztec.moduleSize:=value;
{margin}
val(txtMargin.text,value,dummy);
aztec.margin:=value;
{rune}
if (txtRune.text='') then txtRune.text:='-1';
val(txtRune.text,value,dummy);
aztec.rune:=value;
{correction level}
val(txtEc.text,value,dummy);
aztec.correctionLevel:=value;

aztec.rebuild:=true;

aztec.width:=Image1.width;
aztec.height:=Image1.height;

{structured append}
aztec.structuredAppend:=false;
if (chkStructuredAppend.Checked) then begin
                                 aztec.structuredAppend:=true;
end;

aztec.structuredAppendCounter:=1;
val(txtTotal.text,value,dummy);
aztec.structuredAppendCounter:=value;

aztec.structuredAppendIndex:=1;
val(txtIndex.text,value,dummy);
aztec.structuredAppendindex:=value;

aztec.fileId:=txtFileId.text;

aztec.paintBarcode(Image1.Canvas);

end;


procedure TAztecDemo.FormCreate(Sender: TObject);
begin
aztec:=TAztecCode.Create(nil) ;
aztec.autoConfigurate:=true;
{refresh}
btnRefreshClick(nil);
cEncoding.itemIndex:=0;

end;

end.
