ASP fornece bons objetos integrados para operações de banco de dados. No entanto, faltam outras funções, como a impressão de relatórios. Relatórios nacionais especialmente complexos são difíceis de implementar usando ASP.
No entanto, o ASP oferece suporte a plug-ins, portanto, você pode desenvolver plug-ins ASP conforme necessário. O autor usou Delphi5.0 para desenvolver o componente de impressão ASP. A seguir, o autor desenvolverá passo a passo um componente ASP comum para impressão de relatórios.
A primeira etapa: Crie uma nova biblioteca Activex, denominada PRintT, e a seguir crie uma nova classe de objeto Active Server, denominada Print, ou seja, um componente ASP denominado Print é criado e o arquivo é denominado Unit1.pas.
Passo 2: Abra a Biblioteca de Tipos e crie um novo método Print1 para transferir a impressão do relatório.
Etapa 3: Crie um novo DataModule e coloque o componente Adoconnection e o componente AdoTable. O nome do arquivo é Unit2.pas.
Passo 4: Crie um novo TQuickRep e desenhe o relatório que deseja imprimir. O nome do arquivo é Unit23.pas. A seguir está o código detalhado do arquivo:
{=============Unidade1.pas================}
unidade Unidade1;
interface
usa
ComObj, ActiveX, AspTlb, PrintT_TLB, StdVcl;
tipo
TPrint = classe(TASPObject,iprint)
protegido
procedimento OnEndPage;
procedimento OnStartPage (const AScriptingContext: IUnknown);
procedimento Print1;
fim;
implementação
usa ComServ,unit2,unit23;
procedimento TPrint.OnEndPage;
começar
herdadoOnEndPage;
fim;
procedimento TPrint.OnStartPage(const AScriptingContext: IUnknown);
começar
herdado OnStartPage(AScriptingContext);
fim;
procedimento TPrint.Print1;
começar
IdearRpt.Print;
fim;
inicialização
TAutoObjectFactory.Create(ComServer, TPrint, Class_Print,
ciMultiInstance, tmApartment);
fim.
{===============Unidade2.pas================}
unidade Unidade2;
interface
usa
SysUtils, Windows, Mensagens, Classes, Gráficos, Controles, Formulários,
Diálogos, DBTables, DB, ADODB;
tipo
TCustomerData = classe(TDataModule)
ADOConexão1: Conexão TADO;
ADOTabela1: ADOTabela;
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;
privado
{Declarações privadas}
público
{Declarações públicas}
fim;
var
Dados do Cliente: TCustomerData;
implementação
{$R *.DFM}
fim.
{===========Unidade23.pas===============}
unidade Unidade23;
interface
usa Windows, SysUtils, Mensagens, Classes, Gráficos, Controles,
StdCtrls, ExtCtrls, Formulários, Quickrpt, QRCtrls;
tipo
TIdearRpt = classe(TQuickRep)
PageFooterBand1: Banda TQRB;
PageHeaderBand1: Banda TQRB;
QRLabel1: TQRLabel;
QRLabel2: TQRLabel;
QRLabel3: TQRLabel;
QRDBText15: TQRDBTexto;
QRDBText17: TQRDBTexto;
QRDBText19: TQRDBTexto;
QRDBText13: TQRDBTexto;
QRLabel46: TQRLabel;
QRLabel47:TQRLabel;
TítuloBand1: 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: TQRDBTexto;
QRDBText2: TQRDBTexto;
QRDBText4: TQRDBTexto;
QRDBText6: TQRDBTexto;
QRDBText3: TQRDBTexto;
QRShape9: TQRShape;
QRLabel9: TQRLabel;
QRDBText5: TQRDBTexto;
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: TQRDBTexto;
QRDBText8: TQRDBTexto;
QRDBText9: TQRDBTexto;
QRDBText10: TQRDBTexto;
QRDBText11: TQRDBTexto;
QRDBText12: TQRDBTexto;
QRDBText14: TQRDBTexto;
QRDBText16: TQRDBTexto;
QRDBText18: TQRDBTexto;
QRDBText20: TQRDBTexto;
QRDBText21: TQRDBTexto;
QRDBText22: TQRDBTexto;
QRDBText23: TQRDBTexto;
QRDBText24: TQRDBTexto;
QRDBText25: TQRDBTexto;
QRDBText26: TQRDBTexto;
QRDBText27: TQRDBTexto;
QRDBText28: TQRDBTexto;
QRDBText29: TQRDBTexto;
QRDBText30: TQRDBTexto;
QRDBText31: TQRDBTexto;
QRDBText32: TQRDBTexto;
QRDBText33: TQRDBTexto;
QRDBText34: TQRDBTexto;
QRDBText35: TQRDBTexto;
QRMemo4: TQRMemo;
QRDBText36: TQRDBTexto;
QRDBText37: TQRDBTexto;
QRDBText38: TQRDBTexto;
privado
público
fim;
var
IdearRpt: TIdearRpt;
implementação
usa unidade2;
{$R *.DFM}
fim.
{==========PrintT.dpr============}
biblioteca ImprimirT;
{%Arquivo 'Imprimir.asp'}
usa
ComServ,
PrintT_TLB em 'PrintT_TLB.pas',
Unidade1 em 'Unit1.pas' {Imprimir: CoClass},
Unidade2 em 'Unit2.pas' {CustomerData: TDataModule},
Unit23 em 'Unit23.pas' {IdearRpt: TQuickRep};
exportações
DllGetClassObject,
DllCanUnloadAgora,
DllRegisterServer,
DllUnregisterServer;
{$R *.TLB}
{$R *.RES}
começar
IdearRpt := TIdearRPt.Create(NiL);{essencial}
fim.
Etapa 5: Compile e registre o componente PrintT, que pode ser chamado no código ASP. O exemplo de chamada é o seguinte:
<% Definir DelphiASPObj = Server.CreateObject("PrintT.Print")
DelphiASPOBj.Print1
%>
Através das etapas acima, desenvolvemos com sucesso um componente ASP com função de relatório usando Delphi. É claro que o autor apenas apresentou uma ideia simples, esperando servir de ponto de partida.