用delphi开发asp的详细步骤和问题,高手快来讨论,帮我解决一下,我调了一天也没搞定(10分)

  • 主题发起人 主题发起人 amartapple
  • 开始时间 开始时间
A

amartapple

Unregistered / Unconfirmed
GUEST, unregistred user!
下面很长,希望您仔细看,不管您解决是否,我想通过大家的讨论你总能学些东西,不管你说的对不对,希望你把知道的都说出来,谢谢,我调了一天了,实在不行了,


1、新建一个 ActiveX Library -名称为:Soft
2、再建一个 Active Server Object -名称为:TodayTop(TodayTop10.pas)
3、再建一个 Data Module
4、在 Data Module 中放入一个 ADOConnection 连接数据库,成功。再放入一个ADOQuery,设置它的Connection为ADOConnection
5、然后在TodayTop中加入一个GetTop10的方法
6、这是TodayTop的代码
//------------------------------------------------------------------------------

unit TodayTopPas;
//------------------------------------------------------------------------------

{$WARN SYMBOL_PLATFORM OFF}
//------------------------------------------------------------------------------

interface

//------------------------------------------------------------------------------

uses
ComObj, ActiveX, AspTlb, soft_TLB, StdVcl, DM1, SysUtils;
//------------------------------------------------------------------------------
type
TTodayTop = class(TASPObject, ITodayTop)
private
FDM:TDM;
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
procedure GetTop10; safecall;
public
procedure Initialize;override;
destructor Destroy;override;
end;
//------------------------------------------------------------------------------

implementation
//------------------------------------------------------------------------------

uses ComServ, Forms;
//------------------------------------------------------------------------------

//加载数据模块
procedure TTodayTop.Initialize;
begin
inherited;
FDM:=TDM.Create(Forms.Application);
end;
//------------------------------------------------------------------------------

//释放数据模块
destructor TTodayTop.Destroy;
begin
inherited;
FDM.Free;
end;
//------------------------------------------------------------------------------

procedure TTodayTop.OnEndPage;
begin
inherited OnEndPage;
end;
//------------------------------------------------------------------------------

procedure TTodayTop.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;
//------------------------------------------------------------------------------

procedure TTodayTop.GetTop10;
var
TodayDate:String;
begin
TodayDate:=DateToStr(Date);
With DM.ADOQuery1 do
begin
{Close;
Sql.Clear;
Sql.Add('select top 10 id,showname,bb from download '+
'where lasthits='''+TodayDate+''' and stop=0 and '+
'dayhits>0 order by dayhits desc');
Open;

Response.Write('<table width="99%" border="1">');
Response.Write('<tr>');
if(Eof and Bof)then
begin
Response.Write('<td>');
Response.Write('本日没有下载');
Response.Write('</td>');
end
else
begin
While not Eof do
begin
Response.Write('<td>');
Response.Write('<li><A href=list.asp?id='''+FieldByname('id').Value+'''>');
Response.Write(FieldByname('ShowName').Value+' '+FieldByname('bb').Value);
Response.Write('</A></li>');
Response.Write('</td>');
Next;
end;
end;
Response.Write('</tr>');
Response.Write('</table>');}
end;
end;
//------------------------------------------------------------------------------

initialization
TAutoObjectFactory.Create(ComServer, TTodayTop, Class_TodayTop,
ciMultiInstance, tmApartment);
//------------------------------------------------------------------------------

end.

//------------------------------------------------------------------------------

7、编译生成 Soft.dll 文件
8、在 TodayTopAsp.asp 中调用这个对象,如下:
//------------------------------------------------------------------------------
<%@language=Jscript%>
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your Delphi Active Server method below </H3>
</CENTER>
<HR>
<%
var DelphiASPObj;
DelphiASPObj = Server.CreateObject("soft.TodayTop");
DelphiASPObj.GetTop10();

%>
<HR>
</BODY>
</HTML>
//------------------------------------------------------------------------------

9、用iis搭建服务器,访问出现错误 500.100

请大家仔细看看,帮我查查原因,非常感谢
 
大家知道什么就说点什么么,没准讨论一下就解决了,哈哈

up一下
 
我也在做这方面的东西,我在这里问过,很少人回答的。
不知道是不是你的dll没注册好呢》?
 
做過,沒發現這樣的問題
 
那请楼上两位看看我的代码有没有问题,或者你们的代码给我参考下,谢谢
 
可以用Data Module吗?我没试过,如果用原生ADO,我试过是可以的!
 
别忘了调用CoInitialize
 
to snake:
找不到CoInitialize
 
很早以前 写过不少这种东西

//释放数据模块
destructor TTodayTop.Destroy;
begin
inherited;
FDM.Free;
end;

建议把FDM.Free放前面
 
谢谢楼上,请问你还有没有能调试成功的代码,给我参考一下

amartapple@sina.com
 
不懂也UP一下!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
// --------------
// 下面的代码是返回一个RecordSet 供ASP使用,
// 原来我写过一篇教程 不过现在找不到了
// --------------

unit unit_ASPCom;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
ComObj, ActiveX, AspTlb, myAspCom_TLB, StdVcl,ADODB_TLB , unit_ASPCOM_DM;

type
TASPCom = class(TASPObject, IASPCom)
private
FDM : TDataModule1;
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
function Get_ADORecordSet: Recordset; safecall;
public
procedure Initialize ; override;
destructor Destroy ; override;
end;

implementation

uses ComServ;

procedure TASPCom.OnEndPage;
begin
inherited OnEndPage;
end;

procedure TASPCom.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;

function TASPCom.Get_ADORecordSet: Recordset;
begin
Result := nil;
try
with FDM.ADOQuery1 do
begin
if Active then Close;
SQL.Clear;
SQL.Add('SELECT * FROM Customer');
Open;
end;
Result := FDM.ADOQuery1.Recordset as RecordSet ;
except
; // To Do Something
end;

end;

destructor TASPCom.Destroy;
begin
if FDM.ADOQuery1.Active then FDM.ADOQuery1.Close;
FDM.Free;
inherited;
end;

procedure TASPCom.Initialize;
begin
inherited;
try
FDM := TDataModule1.Create(nil);
except
; // Do something
end;
end;

initialization
TAutoObjectFactory.Create(ComServer, TASPCom, Class_ASPCom,
ciMultiInstance, tmApartment);
end.
 
后退
顶部