如果你想脱离asp爱好者的水平,那么你就应该学会为asp编写组件。我在google上搜索了一下,Delphi编写asp组件的文章一共就几篇,所以今天写了这篇Delphi编写asp组件的基础文章,希望对新手有点帮助。 开始吧,让我们一起编写一个”hello world!”的示例。我这里用的是Delphi 7。 1.文件->新建->其他->ActiveX->ActiveX Library,然后保存成showdll.dpr 2.再次,文件->新建->其他->ActiveX->ActiveX Server Object,填写CoClassName:showhello,其他不变,点击ok。
unit show;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses ComObj, ActiveX, AspTlb, showdll_TLB, StdVcl;
type Tshowhello = class(TASPObject, Ishowhello) protected procedure OnEndPage; safecall; procedure OnStartPage(const AScriptingContext: IUnknown); safecall; procedure sayworld; safecall; //sayworld方法 end;
implementation
uses ComServ;
procedure Tshowhello.OnEndPage; begin inherited OnEndPage; end;
procedure Tshowhello.OnStartPage(const AScriptingContext: IUnknown); begin inherited OnStartPage(AScriptingContext); end; procedure Tshowhello.sayworld(); //定义sayworld方法 begin response.Write('Hello world'); //里边的语法和asp一样的写法了,就在这里封装了。 end;
initialization TAutoObjectFactory.Create(ComServer, Tshowhello, Class_showhello, ciMultiInstance, tmApartment); end. 4.点击运行,编译成dll, 并自动注册了。这时候会提示:
<HTML> <BODY> <TITLE> Testing Delphi ASP </TITLE> <CENTER> <H3> You should see the results of your Delphi Active Server method below </H3> </CENTER> <HR> <% Set DelphiASPObj = Server.CreateObject("showdll.showhello") DelphiASPObj.sayworld %> <HR> </BODY> </HTML> 在iis的站点下运行看看效果吧:
Delphi编写的组件,用win2000的组件服务注册后可以看该组件的接口的方法
写这些,文字不多,就是截图麻烦了点。水平有限,错误的地方,大家拍砖,拍的轻点啊!!!! 一风一云 2004-10-18 |
温馨提示:喜欢本站的话,请收藏一下本站!