unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, Grids, DBGrids, ZAbstractRODataset, ZAbstractDataset,
  ZAbstractTable, ZDataset, ZConnection, StdCtrls, jpeg, ExtCtrls, RSPrint,
  Mask, Buttons;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Panel2: TPanel;
    rs: TRSPrinter;
    ZConnection1: TZConnection;
    ZQuery1: TZQuery;
    DBGrid1: TDBGrid;
    DataSource1: TDataSource;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    MaskEdit3: TMaskEdit;
    MaskEdit4: TMaskEdit;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
	linha:integer;
begin
	//inicio do documento
	rs.BeginDoc;

   //impressao do cabeçalho
   rs.Write(2,50,'X');
   rs.Write(7,8,Edit1.Text);
   rs.Write(7,50,MaskEdit1.Text);
   rs.Write(8,8,Edit2.Text);
   rs.Write(8,45,Edit3.Text);
   rs.Write(8,56,MaskEdit2.Text);
   rs.Write(9,8,Edit4.Text);
   rs.Write(9,36,MaskEdit3.Text);
   rs.Write(9,46,Edit5.Text);

   //impressao dos produtos
   ZQuery1.First;
   linha := 14;
   while not ZQuery1.Eof do begin
   	rs.WriteFont(linha,8,ZQuery1.FieldByName('codpro').AsString,[Compress]);
   	rs.WriteFont(linha,24,ZQuery1.FieldByName('descricao').AsString,[Compress]);
   	rs.WriteFont(linha,41,ZQuery1.FieldByName('unidade').AsString,[Compress]);
   	rs.WriteFont(linha,45,ZQuery1.FieldByName('qtde').AsString,[Compress]);
   	rs.WriteFont(linha,50,ZQuery1.FieldByName('vlrunitario').AsString,[Compress]);
   	rs.WriteFont(linha,60,ZQuery1.FieldByName('vlrtotal').AsString,[Compress]);
      inc(linha);
      ZQuery1.Next;
   end;

   //visualização do relatorio
   rs.PreviewReal;
end;

end.
