ASP provides good embedded objects for database operations. However, other functions are lacking, such as report printing. Especially complex domestic reports are difficult to implement using ASP.
However, ASP supports plug-ins, so you can develop ASP plug-ins as needed. The author developed the ASP printing component using Delphi5.0. Next, the author will develop a common ASP component for report printing step by step.
The first step: Create a new Activex Library, named PRintT, and then create a new Active Server Object Class, named Print, that is, an ASP component named Print is created, and the file is named Unit1.pas.
Step 2: Open the Type Library and create a new method Print1 to transfer report printing.
Step 3: Create a new DataModule and put in the Adoconnection component and AdoTable component. The file name is Unit2.pas.
Step 4: Create a new TQuickRep and design the report you want to print. The file name is Unit23.pas. The following is the detailed code of the file:
{=============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
inheritedOnEndPage;
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);{essential}
end.
Step 5: Compile and register the PrintT component, which can be called in the ASP code. The calling example is as follows:
<% Set DelphiASPObj = Server.CreateObject("PrintT.Print")
DelphiASPOBj.Print1
%>
Through the above steps, we have successfully developed an ASP component with reporting function using Delphi. Of course, the author just introduced a simple idea, hoping to serve as a starting point.