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===============