Do you receive the Programmer's Heaven newsletter? If not, why not subscribe?

View \UNIT1.PAS

Component PrintControl: Preview and print any control

Submitted By: Unknown
Rating: (Not rated) (Rate It)


unit Unit1;
(***************************************************************************)
(*                                                                         *)
(*   #####    #####     #####   #####    #####    ####    ######  #######  *)
(*  #        #     #   #          #     #        #    #   #          #     *)
(*  #        #     #   #  ###     #      ####    #    #   ###        #     *)
(*  #        #     #   #    #     #          #   #    #   #          #     *)
(*   #####    #####     #####   #####   #####     ####    #          #     *)
(*                                                                         *)
(***************************************************************************)
{
 (c) 1995 Cogisoft
 This component is FREE distribution. Use it for your own utilization.
 But you can't sell an application, using this component, without the
 authorization of Cogisoft.

 COGISOFT,H?tel de M?zi?res,19 rue Michel Le Comte,75003 PARIS,FRANCE
 Tel:(33)(1)40-65-04-04, FAX:(33)(1)42-72-27-87

 Jerome VOLLET, CompuServe : 100560,3342
}

interface

uses
        SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, Grids, DBGrids, DB, DBTables,
  PrtCtrl, ToCtrl, DBCtrls;

type
  TfmMain = class(TForm)
    Button1: TButton;
    tbCustomer: TTable;
    dsCustomer: TDataSource;
    Button2: TButton;
    PrintControl1: TPrintControl;
    Button5: TButton;
    PanelOrders: TPanel;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    DBText1: TDBText;
    DBText2: TDBText;
    DBText3: TDBText;
    DBText4: TDBText;
    DBText5: TDBText;
    DBText6: TDBText;
    DBText7: TDBText;
    DBText8: TDBText;
    tbOrders: TTable;
    dsOrders: TDataSource;
    tbOrdersOrderNo: TFloatField;
    tbOrdersCustNo: TFloatField;
    tbOrdersSaleDate: TDateTimeField;
    tbOrdersShipDate: TDateTimeField;
    tbOrdersEmpNo: TIntegerField;
    tbOrdersShipToContact: TStringField;
    tbOrdersShipToAddr1: TStringField;
    tbOrdersShipToAddr2: TStringField;
    tbOrdersShipToCity: TStringField;
    tbOrdersShipToState: TStringField;
    tbOrdersShipToZip: TStringField;
    tbOrdersShipToCountry: TStringField;
    tbOrdersShipToPhone: TStringField;
    tbOrdersShipVIA: TStringField;
    tbOrdersPO: TStringField;
    tbOrdersTerms: TStringField;
    tbOrdersPaymentMethod: TStringField;
    tbOrdersItemsTotal: TCurrencyField;
    tbOrdersTaxRate: TFloatField;
    tbOrdersFreight: TCurrencyField;
    tbOrdersAmountPaid: TCurrencyField;
    tbEmployee: TTable;
    tbOrdersEmployee: TStringField;
    Label1: TLabel;
    Button3: TButton;
    PanelBiolife: TPanel;
    tbBiolife: TTable;
    dsBiolife: TDataSource;
    DBText9: TDBText;
    DBImage1: TDBImage;
    DBNavigator2: TDBNavigator;
    Button6: TButton;
    Button4: TButton;
    DBText10: TDBText;
    DBText11: TDBText;
    DBText13: TDBText;
    DBMemo1: TDBMemo;
    Button7: TButton;
    Button8: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure tbOrdersCalcFields(DataSet: TDataset);
    procedure Button6Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
        private
                { Private declarations }
        public
                { Public declarations }
        end;

var
        fmMain: TfmMain;

implementation

{$R *.DFM}
uses Printers;

procedure TfmMain.Button1Click(Sender: TObject);
begin
        PrintControl1.Print( Self );
end;

procedure TfmMain.Button2Click(Sender: TObject);
begin
        PrintControl1.Print( PanelOrders );
end;

procedure TfmMain.Button3Click(Sender: TObject);
begin
        PrintControl1.Preview( Self );
end;

procedure TfmMain.Button5Click(Sender: TObject);
begin
        PrintControl1.Preview( PanelOrders );
end;

procedure TfmMain.tbOrdersCalcFields(DataSet: TDataset);
begin
        tbEmployee.FindKey( [ tbOrdersEmpNo ] );
        tbOrdersEmployee.Value := tbEmployee.FieldByName( 'FirstName' ).AsString+' '+
                                                                                tbEmployee.FieldByName( 'LastName' ).AsString;
end;

procedure TfmMain.Button6Click(Sender: TObject);
begin
        PrintControl1.Preview( PanelBiolife );
end;

procedure TfmMain.Button4Click(Sender: TObject);
begin
        PrintControl1.Print( PanelBiolife );
end;

procedure TfmMain.Button7Click(Sender: TObject);
begin
        PrintControl1.PrintScale := poPrintToFit;
        PrintControl1.Preview( PanelOrders );
        PrintControl1.PrintScale := poProportional;
end;

procedure TfmMain.Button8Click(Sender: TObject);
begin
        PrintControl1.PrintScale := poPrintToFit;
        PrintControl1.Print( PanelOrders );
        PrintControl1.PrintScale := poProportional;
end;

end.

corner
© 1996-2008. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin.
bootstrapLabs Logo A bootstrapLabs project.