ASP provides a good embedded object in terms of database operation. However, other features have lack, such as: report printing. Especially the complex statements in China, it is difficult to achieve with ASP.
However, ASP supports plug-ins, which can develop ASP plugins as needed, and the author develops ASP print components with Delphi 5.0. The author will step by step to develop a universal report printing ASP component.
Step 1: New ActiveX Library, named Printt, then create an Active Server Object Class, named Print, and establish an ASP component named Print, file named Unit1.PAS.
Step 2: Open Type Library, create a new method Print1 to deliver a report print.
Step 3: Create a DataModule, put it in the Adoconnection component and the ADOTABLE component, and the file name is Unit2.PAS.
Step 4: Create a new TQUickRep, design the report you want to print, the file name is Unit23.PAS. The following is the detailed code of a file: {=============11.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 oneundpage;
Procedure TPrint.onstartPage (const ascription "; begin inherited onstartpage (ascriptingContext);
Procedure tprint.print1; begin idearrpt.print;
Initialization TautoObjectFactory.create (Comserver, TPrint, Class_Print, CIMULTIINSTANCE, TMAPART); END.
{================ ====================}
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; adotable1Pict; private {private declarations}
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; QRLSHAPE 20: 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; qrdbtext 29: tqrdbtext; qrdbtext30: tqrdbtext; QRD BText31: TQRDBText; QRDBText32: TQRDBText; QRDBText33: TQRDBText; QRDBText34: TQRDBText; QRDBText35: TQRDBText; QRMemo4: TQRMemo; QRDBText36: TQRDBText; QRDBText37: TQRDBText; QRDBText38: TQRDBText; privatepublic
END;
Var Idearrpt: tidearrpt;
ImplementationUses Unit2; {$ r * .dfm}
End.
{========= printt.dpr =============}
Library print;
{% 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); {must {}} END.
Step 5: Compile and register the PrinTt component, you can call in the ASP code, called examples,
<% Set delphiaspobj = server.createObject ("printt.print") Delphiaspobj.print1
%>
Through the above steps, we have developed ASP components with reporting functions using Delphi. Of course, the author just introduced a simple idea, hoping to play the effect of tile jade.