开始吧,让我们一起编写一个”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的组件服务注册后可以看该组件的接口的方法
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论