程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 用Delphi開發報表打印的ASP組件

用Delphi開發報表打印的ASP組件

編輯:Delphi
    ASP在對數據庫操作方面提供了很好的內嵌對象。但是,其他方面的功能有所欠缺,如:報表打印。特別是國內的復雜的報表,用ASP很難實現。

         不過,ASP支持插件,這就可以根據需要開發ASP插件,筆者用Delphi5.0開發了ASP打印組件。下面筆者將分步來開發一個通用的報表打印的ASP組件。

         第一步:新建一個Activex Library,命名為PrintT,然後再新建一個Active Server Object Class,命名為Print,即建立了一個名為Print的ASP組件,文件命名為Unit1.pas。

        第二步:打開Type Library,新建一個方法Print1,用於傳遞報表打印。

        第三步:新建一個DataModule,放入Adoconnection組件和AdoTable組件,文件名為Unit2.pas。

       第四步:新建一個TQuickRep,設計你要打印的報表,文件名為文件名為Unit23.pas。以下是個文件的詳細代碼:
  {=============Unit1.pas===============}

  unit Unit1;

  interface

  uses
    ComObj, ActiveX, ASPTlb, PrintT_TLB, StdVcl;

  type
    TPrint = class(TASPObject, IPrint)
    protected
      procedure OnEndPage; safecall;
      procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
      procedure Print1; safecall;
    end;

  implementation

  uses ComServ,unit2,unit23;

  procedure TPrint.OnEndPage;
  begin
    inherited OnEndPage;
  end;

  procedure TPrint.OnStartPage(const AScriptingContext: IUnknown);
  begin
    inherited OnStartPage(AScriptingContext);
  end;

  procedure TPrint.Print1;
  begin
       IdearRpt.Print;
  end;

  initialization
    TAutoObjectFactory.Create(ComServer, TPrint, Class_Print,
      ciMultiInstance, tmApartment);
  end.

  {===============Unit2.pas===============}

  unit Unit2;

  interface

  uses
    SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms,
    Dialogs, DBTables, DB, ADODB;

  type
    TCustomerData = class(TDataModule)
      ADOConnection1: TADOConnection;
      ADOTable1: TADOTable;
      DataSource1: TDataSource;
      ADOTable1NIANH: TStringFIEld;
      ADOTable1XUH: TStringFIEld;
      ADOTable1SHENQDW: TStringFIEld;
      ADOTable1SHENQRQ: TDateTimeFIEld;
      ADOTable1FARDB: TStringFIEld;
      ADOTable1FARDH: TStringFIEld;
      ADOTable1LIANXR: TStringFIEld;
      ADOTable1LIANXRDH: TStringFIEld;
      ADOTable1DANWZCDZ: TStringFIEld;
      ADOTable1JIANSXZDM: TStringFIEld;
      ADOTable1JIANSGM: TBCDFIEld;
      ADOTable1ZHIGRS: TBCDFIEld;
      ADOTable1YONGDFH: TBCDFIEld;
      ADOTable1RIYSL: TBCDFIEld;
      ADOTable1RIPSL: TBCDFIEld;
      ADOTable1JIANZSJGD: TBCDFIEld;
      ADOTable1RANQYL: TBCDFIEld;
      ADOTable1YONGDYQ: TStringFIEld;
      ADOTable1RELYL: TBCDFIEld;
      ADOTable1JIANSXM: TStringFIEld;
      ADOTable1PIZWH: TStringFIEld;
      ADOTable1JIANSGM2: TBCDFIEld;
      ADOTable1YONGDXZDM: TStringFIEld;
      ADOTable1YONGDWZ: TStringFIEld;
      ADOTable1DONGL: TStringFIEld;
      ADOTable1XIL: TStringFIEld;
      ADOTable1NANL: TStringFIEld;
      ADOTable1BEIL: TStringFIEld;
      ADOTable1CHANG: TBCDFIEld;
      ADOTable1KUAN: TBCDFIEld;
      ADOTable1ZONGMJ1: TBCDFIEld;
      ADOTable1ZONGMJ2: TBCDFIEld;
      ADOTable1YOUXRQ1: TDateTimeFIEld;
      ADOTable1YOUXRQ2: TDateTimeFIEld;
      ADOTable1BEIZ: TStringFIEld;
      ADOTable1JINGB: TStringFIEld;
      ADOTable1SHENH: TStringFIEld;
      ADOTable1SHEND: TStringFIEld;
      ADOTable1SHENDRQ: TDateTimeFIEld;
      ADOTable1PICTURE: TBlobFIEld;

    private
      { Private declarations }
    public
      { Public declarations }
    end;

  var
    CustomerData: TCustomerData;

  implementation

  {$R *.DFM}

   

  end.

  {===========Unit23.pas===============}

  unit Unit23;

  interface

  uses Windows, SysUtils, Messages, Classes, Graphics, Controls,
    StdCtrls, ExtCtrls, Forms, Quickrpt, QRCtrls;

  type
    TIdearRpt = class(TQuickRep)
      PageFooterBand1: TQRBand;
      PageHeaderBand1: TQRBand;
      QRLabel1: TQRLabel;
      QRLabel2: TQRLabel;
      QRLabel3: TQRLabel;
      QRDBText15: TQRDBText;
      QRDBText17: TQRDBText;
      QRDBText19: TQRDBText;
      QRDBText13: TQRDBText;
      QRLabel46: TQRLabel;
      QRLabel47: TQRLabel;
      TitleBand1: TQRBand;
      QRShape1: TQRShape;
      QRShape2: TQRShape;
      QRShape3: TQRShape;
      QRShape4: TQRShape;
      QRShape5: TQRShape;
      QRShape6: TQRShape;
      QRLabel4: TQRLabel;
      QRLabel5: TQRLabel;
      QRLabel6: TQRLabel;
      QRShape7: TQRShape;
      QRShape8: TQRShape;
      QRLabel7: TQRLabel;
      QRLabel8: TQRLabel;
      QRLabel11: TQRLabel;
      QRLabel12: TQRLabel;
      QRDBText1: TQRDBText;
      QRDBText2: TQRDBText;
      QRDBText4: TQRDBText;
      QRDBText6: TQRDBText;
      QRDBText3: TQRDBText;
      QRShape9: TQRShape;
      QRLabel9: TQRLabel;
      QRDBText5: TQRDBText;
      QRShape17: TQRShape;
      QRShape22: TQRShape;
      QRShape23: TQRShape;
      QRShape24: TQRShape;
      QRShape25: TQRShape;
      QRShape26: TQRShape;
      QRShape27: TQRShape;
      QRShape10: TQRShape;
      QRShape11: TQRShape;
      QRShape12: TQRShape;
      QRShape13: TQRShape;
      QRShape18: TQRShape;
      QRShape19: TQRShape;
      QRLabel10: TQRLabel;
      QRLabel13: TQRLabel;
      QRLabel14: TQRLabel;
      QRLabel15: TQRLabel;
      QRLabel16: TQRLabel;
      QRLabel17: TQRLabel;
      QRLabel18: TQRLabel;
      QRLabel19: TQRLabel;
      QRLabel20: TQRLabel;
      QRLabel21: TQRLabel;
      QRLabel22: TQRLabel;
      QRLabel23: TQRLabel;
      QRLabel24: TQRLabel;
      QRLabel32: TQRLabel;
      QRLabel33: TQRLabel;
      QRLabel34: TQRLabel;
      QRLabel35: TQRLabel;
      QRLabel36: TQRLabel;
      QRShape20: TQRShape;
      QRLabel37: TQRLabel;
      QRLabel38: TQRLabel;
      QRLabel41: TQRLabel;
      QRLabel42: TQRLabel;
      QRLabel43: TQRLabel;
      QRLabel44: TQRLabel;
      QRLabel45: TQRLabel;
      QRLabel48: TQRLabel;
      QRLabel49: TQRLabel;
      QRLabel50: TQRLabel;
      QRLabel51: TQRLabel;
      QRLabel52: TQRLabel;
      QRLabel53: TQRLabel;
      QRLabel54: TQRLabel;
      QRLabel55: TQRLabel;
      QRLabel56: TQRLabel;
      QRLabel57: TQRLabel;
      QRLabel58: TQRLabel;
      QRLabel59: TQRLabel;
      QRLabel60: TQRLabel;
      QRLabel61: TQRLabel;
      QRShape28: TQRShape;
      QRLabel62: TQRLabel;
      QRLabel63: TQRLabel;
      QRDBText7: TQRDBText;
      QRDBText8: TQRDBText;
      QRDBText9: TQRDBText;
      QRDBText10: TQRDBText;
      QRDBText11: TQRDBText;
      QRDBText12: TQRDBText;
      QRDBText14: TQRDBText;
      QRDBText16: TQRDBText;
      QRDBText18: TQRDBText;
      QRDBText20: TQRDBText;
      QRDBText21: TQRDBText;
      QRDBText22: TQRDBText;
      QRDBText23: TQRDBText;
      QRDBText24: TQRDBText;
      QRDBText25: TQRDBText;
      QRDBText26: TQRDBText;
      QRDBText27: TQRDBText;
      QRDBText28: TQRDBText;
      QRDBText29: TQRDBText;
      QRDBText30: TQRDBText;
      QRDBText31: TQRDBText;
      QRDBText32: TQRDBText;
      QRDBText33: TQRDBText;
      QRDBText34: TQRDBText;
      QRDBText35: TQRDBText;
      QRMemo4: TQRMemo;
      QRDBText36: TQRDBText;
      QRDBText37: TQRDBText;
      QRDBText38: TQRDBText;
    private

    public

    end;

  var
    IdearRpt: TIdearRpt;

  implementation
  uses unit2;
  {$R *.DFM}

  end.

  {=========PrintT.dpr============}

  library PrintT;

  {%File 'Print.ASP'}

  uses
    ComServ,
    PrintT_TLB in 'PrintT_TLB.pas',
    Unit1 in 'Unit1.pas' {Print: CoClass},
    Unit2 in 'Unit2.pas' {CustomerData: TDataModule},
    Unit23 in 'Unit23.pas' {IdearRpt: TQuickRep};

  exports
    DllGetClassObject,
    DllCanUnloadNow,
    DllRegisterServer,
    DllUnregisterServer;

  {$R *.TLB}

  {$R *.RES}

  begin
       IdearRpt := TIdearRPt.Create(NiL);{必不可少}
  end.

        第五步:編譯並注冊PrintT組件,即可在ASP代碼中調用,調用示例如下:
  

  <% Set DelphiASPObj = Server.CreateObject("PrintT.Print")
     DelphiASPObj.Print1

  %>

      通過以上步驟,我們就順利地利用Delphi開發出了具有報表功能的ASP組件了。當然,筆者只是介紹了一個簡單的思路,希望能起到拋磚引玉之功效。
  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved