如果你想脫離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 |
溫馨提示:喜歡本站的話,請收藏一下本站!